From 604a3bc06281de721e27561341299f1bb9f8ea51 Mon Sep 17 00:00:00 2001 From: cash Date: Sat, 5 Nov 2011 15:05:13 -0400 Subject: Fixes #3976 fixed unit tests for normalizing urls and standardized the code from the previous merge --- js/lib/elgglib.js | 14 ++++++------- js/tests/ElggLibTest.js | 55 +++++++++++++++++++++++++------------------------ 2 files changed, 35 insertions(+), 34 deletions(-) (limited to 'js') diff --git a/js/lib/elgglib.js b/js/lib/elgglib.js index 3e38bbad6..ca7914e7c 100644 --- a/js/lib/elgglib.js +++ b/js/lib/elgglib.js @@ -224,8 +224,8 @@ elgg.provide = function(pkg, opt_context) { * child.foo('boo!'); // alert('boo!'); * * - * @param {Function} childCtor Child class. - * @param {Function} parentCtor Parent class. + * @param {Function} Child Child class constructor. + * @param {Function} Parent Parent class constructor. */ elgg.inherit = function(Child, Parent) { Child.prototype = new Parent(); @@ -250,17 +250,17 @@ elgg.normalize_url = function(url) { url = url || ''; elgg.assertTypeOf('string', url); - validated = (function(url){ + validated = (function(url) { url = elgg.parse_url(url); - if(url.scheme){ + if (url.scheme){ url.scheme = url.scheme.toLowerCase(); } - if(url.scheme == 'http' || url.scheme == 'https') { - if(!url.host) { + if (url.scheme == 'http' || url.scheme == 'https') { + if (!url.host) { return false; } /* hostname labels may contain only alphanumeric characters, dots and hypens. */ - if(!(new RegExp("^([a-zA-Z0-9][a-zA-Z0-9\\-\\.]*)$", "i")).test(url.host) || url.host.charAt(-1) == '.'){ + if (!(new RegExp("^([a-zA-Z0-9][a-zA-Z0-9\\-\\.]*)$", "i")).test(url.host) || url.host.charAt(-1) == '.') { return false; } } diff --git a/js/tests/ElggLibTest.js b/js/tests/ElggLibTest.js index 688a1016c..c53c6331d 100644 --- a/js/tests/ElggLibTest.js +++ b/js/tests/ElggLibTest.js @@ -72,33 +72,34 @@ ElggLibTest.prototype.testNormalizeUrl = function() { elgg.config.wwwroot = "http://elgg.org/"; [ - ['', elgg.config.wwwroot], - ['http://example.com', 'http://example.com'], - ['https://example.com', 'https://example.com'], - ['http://example-time.com', 'http://example-time.com'], - ['//example.com', '//example.com'], - - ['ftp://example.com/file', 'ftp://example.com/file', - ['mailto:brett@elgg.org', 'mailto:brett@elgg.org', - ['javascript:alert("test")', 'javascript:alert("test")', - ['app://endpoint', 'app://endpoint', - - ['example.com', 'http://example.com', - ['example.com/subpage', 'http://example.com/subpage', - - ['page/handler', elgg.config.wwwroot + 'page/handler', - ['page/handler?p=v&p2=v2', elgg.config.wwwroot + 'page/handler?p=v&p2=v2', - ['mod/plugin/file.php', elgg.config.wwwroot + 'mod/plugin/file.php', - ['mod/plugin/file.php?p=v&p2=v2', elgg.config.wwwroot + 'mod/plugin/file.php?p=v&p2=v2', - ['rootfile.php', elgg.config.wwwroot + 'rootfile.php', - ['rootfile.php?p=v&p2=v2', elgg.config.wwwroot + 'rootfile.php?p=v&p2=v2', - - ['/page/handler', elgg.config.wwwroot + 'page/handler', - ['/page/handler?p=v&p2=v2', elgg.config.wwwroot + 'page/handler?p=v&p2=v2', - ['/mod/plugin/file.php', elgg.config.wwwroot + 'mod/plugin/file.php', - ['/mod/plugin/file.php?p=v&p2=v2', elgg.config.wwwroot + 'mod/plugin/file.php?p=v&p2=v2', - ['/rootfile.php', elgg.config.wwwroot + 'rootfile.php', - ['/rootfile.php?p=v&p2=v2', elgg.config.wwwroot + 'rootfile.php?p=v&p2=v2', + ['', elgg.config.wwwroot], + ['test', elgg.config.wwwroot + 'test'], + ['http://example.com', 'http://example.com'], + ['https://example.com', 'https://example.com'], + ['http://example-time.com', 'http://example-time.com'], + ['//example.com', '//example.com'], + + ['ftp://example.com/file', 'ftp://example.com/file'], + ['mailto:brett@elgg.org', 'mailto:brett@elgg.org'], + ['javascript:alert("test")', 'javascript:alert("test")'], + ['app://endpoint', 'app://endpoint'], + + ['example.com', 'http://example.com'], + ['example.com/subpage', 'http://example.com/subpage'], + + ['page/handler', elgg.config.wwwroot + 'page/handler'], + ['page/handler?p=v&p2=v2', elgg.config.wwwroot + 'page/handler?p=v&p2=v2'], + ['mod/plugin/file.php', elgg.config.wwwroot + 'mod/plugin/file.php'], + ['mod/plugin/file.php?p=v&p2=v2', elgg.config.wwwroot + 'mod/plugin/file.php?p=v&p2=v2'], + ['rootfile.php', elgg.config.wwwroot + 'rootfile.php'], + ['rootfile.php?p=v&p2=v2', elgg.config.wwwroot + 'rootfile.php?p=v&p2=v2'], + + ['/page/handler', elgg.config.wwwroot + 'page/handler'], + ['/page/handler?p=v&p2=v2', elgg.config.wwwroot + 'page/handler?p=v&p2=v2'], + ['/mod/plugin/file.php', elgg.config.wwwroot + 'mod/plugin/file.php'], + ['/mod/plugin/file.php?p=v&p2=v2', elgg.config.wwwroot + 'mod/plugin/file.php?p=v&p2=v2'], + ['/rootfile.php', elgg.config.wwwroot + 'rootfile.php'], + ['/rootfile.php?p=v&p2=v2', elgg.config.wwwroot + 'rootfile.php?p=v&p2=v2'], ].forEach(function(args) { assertEquals(args[1], elgg.normalize_url(args[0])); -- cgit v1.2.3