Permalink
Browse files

add tests for mobile path getLocation

  • Loading branch information...
1 parent 75ba273 commit 125260bef91e89dc653fc093beb9a66688f9e42c @johnbender johnbender committed Aug 7, 2012
Showing with 15 additions and 2 deletions.
  1. +2 −2 js/jquery.mobile.navigation.js
  2. +13 −0 tests/unit/navigation/navigation_helpers.js
View
4 js/jquery.mobile.navigation.js
@@ -52,8 +52,8 @@ define( [
// Abstraction to address xss (Issue #4787) in browsers that auto decode the username:pass
// portion of location.href. All references to location.href should be replaced with a call
// to this method so that it can be dealt with properly here
- getLocation: function() {
- var uri = this.parseUrl( location.href ),
+ getLocation: function( url ) {
+ var uri = this.parseUrl( url || location.href ),
encodedUserPass = "";
if( uri.username ){
View
13 tests/unit/navigation/navigation_helpers.js
@@ -238,4 +238,17 @@
deepEqual( $.mobile.path.isPermittedCrossDomainRequest( fileDocUrl, "file://foo"), false, "two file protocol urls fail");
});
+
+ test( "path.getLocation works properly", function() {
+ equal( $.mobile.path.getLocation("http://example.com/"), "http://example.com/" );
+ equal( $.mobile.path.getLocation("http://foo@example.com"), "http://foo@example.com" );
+ equal( $.mobile.path.getLocation("http://foo:bar@example.com"), "http://foo:bar@example.com" );
+ equal( $.mobile.path.getLocation("http://<foo<:bar@example.com"), "http://%3Cfoo%3C:bar@example.com" );
+ equal( $.mobile.path.getLocation("http://foo:<bar<@example.com"), "http://foo:%3Cbar%3C@example.com" );
+ equal( $.mobile.path.getLocation("http://<foo<:<bar<@example.com"), "http://%3Cfoo%3C:%3Cbar%3C@example.com" );
+
+ var allUriParts = "http://jblas:password@mycompany.com:8080/mail/inbox?msg=1234&type=unread#msg-content";
+
+ equal( $.mobile.path.getLocation( allUriParts ), allUriParts );
+ });
})(jQuery);

0 comments on commit 125260b

Please sign in to comment.