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

Commit 11f9546

Browse files
committed
correct query param preservation on urls
1 parent 5bde73a commit 11f9546

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

js/navigation/path.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,14 +297,14 @@ define([
297297
},
298298

299299
squash: function( url, resolutionUrl ) {
300-
var state, href,
301-
isPath = path.isPath( url ),
302-
uri = path.parseUrl( url ),
300+
var state, href, cleanedUrl, search, stateIndex,
301+
isPath = this.isPath( url ),
302+
uri = this.parseUrl( url ),
303303
preservedHash = uri.hash,
304-
cleanedUrl,
305-
uiState = "", stateIndex;
304+
uiState = "";
306305

307-
resolutionUrl = resolutionUrl || (path.isPath(url) ? path.getLocation() : $.mobile.getDocumentUrl());
306+
// produce a url against which we can resole the provided path
307+
resolutionUrl = resolutionUrl || (path.isPath(url) ? path.getLocation() : path.getDocumentUrl());
308308

309309
// If the url is anything but a simple string, remove any preceding hash
310310
// eg #foo/bar -> foo/bar
@@ -327,6 +327,10 @@ define([
327327
// make the cleanedUrl absolute relative to the resolution url
328328
href = path.makeUrlAbsolute( cleanedUrl, resolutionUrl );
329329

330+
// grab the search from the resolved url since parsing from
331+
// the passed url may not yield the correct result
332+
search = this.parseUrl( href ).search;
333+
330334
// TODO all this crap is terrible, clean it up
331335
if ( isPath ) {
332336
// Get a hash where possible and, as long as it's not a path
@@ -351,7 +355,7 @@ define([
351355

352356
// reconstruct each of the pieces with the new search string and hash
353357
href = path.parseUrl( href );
354-
href = href.protocol + "//" + href.host + href.pathname + uri.search + preservedHash;
358+
href = href.protocol + "//" + href.host + href.pathname + search + preservedHash;
355359
} else {
356360
href += href.indexOf( "#" ) > -1 ? uiState : "#" + uiState;
357361
}

tests/unit/path/path_core.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,5 +288,7 @@
288288

289289
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" );
290290

291+
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" );
292+
291293
});
292294
})(jQuery);

0 commit comments

Comments
 (0)