Permalink
Browse files

correct query param preservation on urls

  • Loading branch information...
johnbender committed Dec 18, 2012
1 parent 5bde73a commit 11f9546e6021d880a1be80bc03716ddd6bf85c13
Showing with 13 additions and 7 deletions.
  1. +11 −7 js/navigation/path.js
  2. +2 −0 tests/unit/path/path_core.js
View
@@ -297,14 +297,14 @@ define([
},
squash: function( url, resolutionUrl ) {
var state, href,
isPath = path.isPath( url ),
uri = path.parseUrl( url ),
var state, href, cleanedUrl, search, stateIndex,
isPath = this.isPath( url ),
uri = this.parseUrl( url ),
preservedHash = uri.hash,
cleanedUrl,
uiState = "", stateIndex;
uiState = "";
resolutionUrl = resolutionUrl || (path.isPath(url) ? path.getLocation() : $.mobile.getDocumentUrl());
// produce a url against which we can resole the provided path
resolutionUrl = resolutionUrl || (path.isPath(url) ? path.getLocation() : path.getDocumentUrl());
// If the url is anything but a simple string, remove any preceding hash
// eg #foo/bar -> foo/bar
@@ -327,6 +327,10 @@ define([
// make the cleanedUrl absolute relative to the resolution url
href = path.makeUrlAbsolute( cleanedUrl, resolutionUrl );
// grab the search from the resolved url since parsing from
// the passed url may not yield the correct result
search = this.parseUrl( href ).search;
// TODO all this crap is terrible, clean it up
if ( isPath ) {
// Get a hash where possible and, as long as it's not a path
@@ -351,7 +355,7 @@ define([
// reconstruct each of the pieces with the new search string and hash
href = path.parseUrl( href );
href = href.protocol + "//" + href.host + href.pathname + uri.search + preservedHash;
href = href.protocol + "//" + href.host + href.pathname + search + preservedHash;
} else {
href += href.indexOf( "#" ) > -1 ? uiState : "#" + uiState;
}
@@ -288,5 +288,7 @@
equal( squash("#foo&ui-state=foo", "http://example.com/"), "http://example.com/#foo&ui-state=foo", "ui-state keys attached to simple string hashes are preserved" );
equal( squash("#/foo/bar/?foo=bar&baz=bak", "http://example.com/"), "http://example.com/foo/bar/?foo=bar&baz=bak", "ui-state keys attached to simple string hashes are preserved" );
});
})(jQuery);

0 comments on commit 11f9546

Please sign in to comment.