Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

Commit b068128

Browse files
author
Gabriel Schulhof
committed
Navigation: Compare domains case-insensitively inside $.mobile.path
(cherry picked from commit ba92be4) Closes gh-7486 Fixes gh-2446
1 parent e8c0118 commit b068128

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

js/navigation/path.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ define([
154154

155155
//Returns true if both urls have the same domain.
156156
isSameDomain: function( absUrl1, absUrl2 ) {
157-
return path.parseUrl( absUrl1 ).domain === path.parseUrl( absUrl2 ).domain;
157+
return path.parseUrl( absUrl1 ).domain.toLowerCase() ===
158+
path.parseUrl( absUrl2 ).domain.toLowerCase();
158159
},
159160

160161
//Returns true for any relative variant.
@@ -262,7 +263,9 @@ define([
262263
//could be mailto, etc
263264
isExternal: function( url ) {
264265
var u = path.parseUrl( url );
265-
return u.protocol && u.domain !== this.documentUrl.domain ? true : false;
266+
267+
return !!( u.protocol &&
268+
( u.domain.toLowerCase() !== this.documentUrl.domain.toLowerCase() ) );
266269
},
267270

268271
hasProtocol: function( url ) {

tests/unit/path/path_core.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,4 +295,34 @@
295295
equal( squash("#foo", "http://example.com/?foo=bar&baz=bak"), "http://example.com/?foo=bar&baz=bak#foo", "ui-state keys attached to simple string hashes are preserved" );
296296

297297
});
298+
299+
test( "isSameDomain() compares domains case-insensitively", function() {
300+
deepEqual(
301+
$.mobile.path.isSameDomain(
302+
"http://example.com/path/to/filename.html",
303+
"http://EXAmPLE.cOm/path/to/filename.html" ),
304+
true,
305+
"Domain comparison was case-insensitive" );
306+
});
307+
308+
( function() {
309+
310+
var originalDocumentUrl,
311+
path = $.mobile.path;
312+
313+
module( "$.mobile.path.isExternal()", {
314+
setup: function() {
315+
originalDocumentUrl = path.documentUrl;
316+
path.documentUrl = path.parseUrl( "http://example.com/path/to/filename.html" );
317+
},
318+
teardown: function() {
319+
path.documentUrl = originalDocumentUrl;
320+
}
321+
});
322+
323+
test( "$.mobile.path.isExternal() compares domains case-insensitively", function() {
324+
deepEqual( path.isExternal( "http://EXAmPLE.CoM/path/to/other-filename.html" ), false,
325+
"Domain comparison was case-insensitive" );
326+
});
327+
})();
298328
})(jQuery);

0 commit comments

Comments
 (0)