Commit 541fba3d 541fba3dcbdea007945e0bf51a222d10c377472d by Nicolas Perriault

fixed broken utils.cleanUrl()

1 parent 8fc28ab6
...@@ -57,11 +57,16 @@ ...@@ -57,11 +57,16 @@
57 * @return String 57 * @return String
58 */ 58 */
59 function cleanUrl(url) { 59 function cleanUrl(url) {
60 var match = /(https?):\/\/(.*)/i.exec(url); 60 var parts = /(https?):\/\/(.*)/i.exec(url);
61 if (!match || match.length !== 3) { 61 if (!parts) {
62 return url; 62 return url;
63 } 63 }
64 return format("%s://%s/", match[1], match[2]); // notice the trailing slash 64 var protocol = parts[1];
65 var subparts = parts[2].split('/');
66 if (subparts.length === 1) {
67 return format("%s://%s/", protocol, subparts[0]);
68 }
69 return url;
65 } 70 }
66 exports.cleanUrl = cleanUrl; 71 exports.cleanUrl = cleanUrl;
67 72
......
...@@ -13,35 +13,39 @@ t.comment('cleanUrl()'); ...@@ -13,35 +13,39 @@ t.comment('cleanUrl()');
13 'https://google.com': 'https://google.com/', 13 'https://google.com': 'https://google.com/',
14 'https://www.google.com/': 'https://www.google.com/', 14 'https://www.google.com/': 'https://www.google.com/',
15 'https://www.google.com/?plop=2': 'https://www.google.com/?plop=2', 15 'https://www.google.com/?plop=2': 'https://www.google.com/?plop=2',
16 'file:///Users/toto/toto.html': 'file:///Users/toto/toto.html' 16 'file:///Users/toto/toto.html': 'file:///Users/toto/toto.html',
17 '/100': '/100'
17 }; 18 };
19 for (var testCase in testCases) {
20 t.assertEquals(utils.cleanUrl(testCase), testCases[testCase], 'cleanUrl() cleans an URL');
21 }
18 })(); 22 })();
19 23
20 t.comment('equals()'); 24 t.comment('equals()');
21 (function() { 25 (function() {
22 t.assert(utils.equals(null, null), 'Tester.testEquals() null equality'); 26 t.assert(utils.equals(null, null), 'equals() null equality');
23 t.assertNot(utils.equals(null, undefined), 'Tester.testEquals() null vs. undefined inequality'); 27 t.assertNot(utils.equals(null, undefined), 'equals() null vs. undefined inequality');
24 t.assert(utils.equals("hi", "hi"), 'Tester.testEquals() string equality'); 28 t.assert(utils.equals("hi", "hi"), 'equals() string equality');
25 t.assertNot(utils.equals("hi", "ih"), 'Tester.testEquals() string inequality'); 29 t.assertNot(utils.equals("hi", "ih"), 'equals() string inequality');
26 t.assert(utils.equals(5, 5), 'Tester.testEquals() number equality'); 30 t.assert(utils.equals(5, 5), 'equals() number equality');
27 t.assertNot(utils.equals("5", 5), 'Tester.testEquals() number equality without implicit cast'); 31 t.assertNot(utils.equals("5", 5), 'equals() number equality without implicit cast');
28 t.assert(utils.equals(5, 5.0), 'Tester.testEquals() number equality with cast'); 32 t.assert(utils.equals(5, 5.0), 'equals() number equality with cast');
29 t.assertNot(utils.equals(5, 10), 'Tester.testEquals() number inequality'); 33 t.assertNot(utils.equals(5, 10), 'equals() number inequality');
30 t.assert(utils.equals([], []), 'Tester.testEquals() empty array equality'); 34 t.assert(utils.equals([], []), 'equals() empty array equality');
31 t.assert(utils.equals([1,2], [1,2]), 'Tester.testEquals() array equality'); 35 t.assert(utils.equals([1,2], [1,2]), 'equals() array equality');
32 t.assert(utils.equals([1,2,[1,2,function(){}]], [1,2,[1,2,function(){}]]), 'Tester.testEquals() complex array equality'); 36 t.assert(utils.equals([1,2,[1,2,function(){}]], [1,2,[1,2,function(){}]]), 'equals() complex array equality');
33 t.assertNot(utils.equals([1,2,[1,2,function(a){}]], [1,2,[1,2,function(b){}]]), 'Tester.testEquals() complex array inequality'); 37 t.assertNot(utils.equals([1,2,[1,2,function(a){}]], [1,2,[1,2,function(b){}]]), 'equals() complex array inequality');
34 t.assertNot(utils.equals([1,2], [2,1]), 'Tester.testEquals() shuffled array inequality'); 38 t.assertNot(utils.equals([1,2], [2,1]), 'equals() shuffled array inequality');
35 t.assertNot(utils.equals([1,2], [1,2,3]), 'Tester.testEquals() array length inequality'); 39 t.assertNot(utils.equals([1,2], [1,2,3]), 'equals() array length inequality');
36 t.assert(utils.equals({}, {}), 'Tester.testEquals() empty object equality'); 40 t.assert(utils.equals({}, {}), 'equals() empty object equality');
37 t.assert(utils.equals({a:1,b:2}, {a:1,b:2}), 'Tester.testEquals() object length equality'); 41 t.assert(utils.equals({a:1,b:2}, {a:1,b:2}), 'equals() object length equality');
38 t.assert(utils.equals({a:1,b:2}, {b:2,a:1}), 'Tester.testEquals() shuffled object keys equality'); 42 t.assert(utils.equals({a:1,b:2}, {b:2,a:1}), 'equals() shuffled object keys equality');
39 t.assertNot(utils.equals({a:1,b:2}, {a:1,b:3}), 'Tester.testEquals() object inequality'); 43 t.assertNot(utils.equals({a:1,b:2}, {a:1,b:3}), 'equals() object inequality');
40 t.assert(utils.equals({1:{name:"bob",age:28}, 2:{name:"john",age:26}}, {1:{name:"bob",age:28}, 2:{name:"john",age:26}}), 'Tester.testEquals() complex object equality'); 44 t.assert(utils.equals({1:{name:"bob",age:28}, 2:{name:"john",age:26}}, {1:{name:"bob",age:28}, 2:{name:"john",age:26}}), 'equals() complex object equality');
41 t.assertNot(utils.equals({1:{name:"bob",age:28}, 2:{name:"john",age:26}}, {1:{name:"bob",age:28}, 2:{name:"john",age:27}}), 'Tester.testEquals() complex object inequality'); 45 t.assertNot(utils.equals({1:{name:"bob",age:28}, 2:{name:"john",age:26}}, {1:{name:"bob",age:28}, 2:{name:"john",age:27}}), 'equals() complex object inequality');
42 t.assert(utils.equals(function(x){return x;}, function(x){return x;}), 'Tester.testEquals() function equality'); 46 t.assert(utils.equals(function(x){return x;}, function(x){return x;}), 'equals() function equality');
43 t.assertNot(utils.equals(function(x){return x;}, function(y){return y+2;}), 'Tester.testEquals() function inequality'); 47 t.assertNot(utils.equals(function(x){return x;}, function(y){return y+2;}), 'equals() function inequality');
44 t.assert(utils.equals([{a:1, b:2}, {c:3, d:4}], [{a:1, b:2}, {c:3, d:4}]), 'Tester.testEquals() arrays of objects'); 48 t.assert(utils.equals([{a:1, b:2}, {c:3, d:4}], [{a:1, b:2}, {c:3, d:4}]), 'equals() arrays of objects');
45 })(); 49 })();
46 50
47 t.comment('fileExt()'); 51 t.comment('fileExt()');
......