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

Commit

Permalink
replace location.href references with a centralized method so we can …
Browse files Browse the repository at this point in the history
…address #4787
  • Loading branch information
johnbender committed Aug 6, 2012
1 parent 40735e2 commit 4348eac
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion js/jquery.mobile.init.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ define( [ "jquery", "./jquery.mobile.core", "./jquery.mobile.support", "./jquery

// Store the initial destination
if ( $.mobile.path.isHashValid( location.hash ) ) {
$.mobile.urlHistory.initialDst = $.mobile.path.parseUrl( location.href ).hash.replace( "#", "" );
$.mobile.urlHistory.initialDst = $.mobile.path.parseLocation().hash.replace( "#", "" );
}
$.mobile.changePage( $.mobile.firstPage, { transition: "none", reverse: true, changeHash: false, fromHashChange: true } );
}
Expand Down
15 changes: 13 additions & 2 deletions js/jquery.mobile.navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ define( [
//
urlParseRE: /^(((([^:\/#\?]+:)?(?:(\/\/)((?:(([^:@\/#\?]+)(?:\:([^:@\/#\?]+))?)@)?(([^:\/#\?\]\[]+|\[[^\/\]@#?]+\])(?:\:([0-9]+))?))?)?)?((\/?(?:[^\/\?#]+\/+)*)([^\?#]*)))?(\?[^#]+)?)(#.*)?/,

// Abstraction to address xss (Issue #4787) in browsers that auto decode 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() {
return window.location.toString();
},

parseLocation: function() {
return this.parseUrl( this.getLocation() );
},

//Parse a URL into a structure that allows easy access to
//all of the URL components by name.
parseUrl: function( url ) {
Expand Down Expand Up @@ -369,7 +380,7 @@ define( [
$base = $head.children( "base" ),

//tuck away the original document URL minus any fragment.
documentUrl = path.parseUrl( location.href ),
documentUrl = path.parseLocation(),

//if the document has an embedded base tag, documentBase is set to its
//initial value. If a base tag does not exist, then we default to the documentUrl.
Expand Down Expand Up @@ -1500,7 +1511,7 @@ define( [
$window.bind( "hashchange", function( e, triggered ) {
// Firefox auto-escapes the location.hash as for v13 but
// leaves the href untouched
$.mobile._handleHashChange( path.parseUrl(location.href).hash );
$.mobile._handleHashChange( path.parseLocation().hash );
});

//set page min-heights to be device specific
Expand Down
10 changes: 5 additions & 5 deletions js/jquery.mobile.navigation.pushstate.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ define( [ "jquery", "./jquery.mobile.navigation", "depend!./jquery.hashchange[jq
var pushStateHandler = {},
self = pushStateHandler,
$win = $( window ),
url = $.mobile.path.parseUrl( location.href ),
url = $.mobile.path.parseLocation(),
mobileinitDeferred = $.Deferred(),
domreadyDeferred = $.Deferred();

Expand All @@ -35,7 +35,7 @@ define( [ "jquery", "./jquery.mobile.navigation", "depend!./jquery.hashchange[jq
state: function() {
return {
// firefox auto decodes the url when using location.hash but not href
hash: $.mobile.path.parseUrl( location.href ).hash || "#" + self.initialFilePath,
hash: $.mobile.path.parseLocation().hash || "#" + self.initialFilePath,
title: document.title,

// persist across refresh
Expand Down Expand Up @@ -74,9 +74,9 @@ define( [ "jquery", "./jquery.mobile.navigation", "depend!./jquery.hashchange[jq

var href, state,
// firefox auto decodes the url when using location.hash but not href
hash = $.mobile.path.parseUrl( location.href ).hash,
hash = $.mobile.path.parseLocation().hash,
isPath = $.mobile.path.isPath( hash ),
resolutionUrl = isPath ? location.href : $.mobile.getDocumentUrl();
resolutionUrl = isPath ? $.mobile.path.getLocation() : $.mobile.getDocumentUrl();

hash = isPath ? hash.replace( "#", "" ) : hash;

Expand Down Expand Up @@ -141,7 +141,7 @@ define( [ "jquery", "./jquery.mobile.navigation", "depend!./jquery.hashchange[jq

// if there's no hash, we need to replacestate for returning to home
if ( location.hash === "" ) {
history.replaceState( self.state(), document.title, location.href );
history.replaceState( self.state(), document.title, $.mobile.path.getLocation() );
}
}
});
Expand Down

0 comments on commit 4348eac

Please sign in to comment.