]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Fixes #3976 fixed unit tests for normalizing urls and standardized the code from...
authorcash <cash.costello@gmail.com>
Sat, 5 Nov 2011 19:05:13 +0000 (15:05 -0400)
committercash <cash.costello@gmail.com>
Sat, 5 Nov 2011 19:05:13 +0000 (15:05 -0400)
js/lib/elgglib.js
js/tests/ElggLibTest.js

index 3e38bbad65058ed6726b39326454f82fd48cbe68..ca7914e7cd9f34103ccb6393a64d803f70e29a3d 100644 (file)
@@ -224,8 +224,8 @@ elgg.provide = function(pkg, opt_context) {
  * child.foo('boo!'); // alert('boo!');
  * </pre>
  *
- * @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;
                        }
                }
index 688a1016cdcd4230a2563e2a1e8ed1838ebbadc8..c53c6331dffe5c6ba62e85145c59c9545e99e5ba 100644 (file)
@@ -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]));