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

Commit

Permalink
Navigation: Compare domains case-insensitively inside $.mobile.path
Browse files Browse the repository at this point in the history
Closes gh-7486
Fixes gh-2446
  • Loading branch information
Gabriel Schulhof committed Jul 30, 2014
1 parent 7d361e9 commit ba92be4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
7 changes: 5 additions & 2 deletions js/navigation/path.js
Expand Up @@ -154,7 +154,8 @@ define([

//Returns true if both urls have the same domain.
isSameDomain: function( absUrl1, absUrl2 ) {
return path.parseUrl( absUrl1 ).domain === path.parseUrl( absUrl2 ).domain;
return path.parseUrl( absUrl1 ).domain.toLowerCase() ===
path.parseUrl( absUrl2 ).domain.toLowerCase();
},

//Returns true for any relative variant.
Expand Down Expand Up @@ -262,7 +263,9 @@ define([
//could be mailto, etc
isExternal: function( url ) {
var u = path.parseUrl( url );
return u.protocol && u.domain !== this.documentUrl.domain ? true : false;

return !!( u.protocol &&
( u.domain.toLowerCase() !== this.documentUrl.domain.toLowerCase() ) );
},

hasProtocol: function( url ) {
Expand Down
30 changes: 30 additions & 0 deletions tests/unit/path/path_core.js
Expand Up @@ -295,4 +295,34 @@
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" );

});

test( "isSameDomain() compares domains case-insensitively", function() {
deepEqual(
$.mobile.path.isSameDomain(
"http://example.com/path/to/filename.html",
"http://EXAmPLE.cOm/path/to/filename.html" ),
true,
"Domain comparison was case-insensitive" );
});

( function() {

var originalDocumentUrl,
path = $.mobile.path;

module( "$.mobile.path.isExternal()", {
setup: function() {
originalDocumentUrl = path.documentUrl;
path.documentUrl = path.parseUrl( "http://example.com/path/to/filename.html" );
},
teardown: function() {
path.documentUrl = originalDocumentUrl;
}
});

test( "$.mobile.path.isExternal() compares domains case-insensitively", function() {
deepEqual( path.isExternal( "http://EXAmPLE.CoM/path/to/other-filename.html" ), false,
"Domain comparison was case-insensitive" );
});
})();
})(jQuery);

0 comments on commit ba92be4

Please sign in to comment.