Skip to content
This repository
Browse code

correct query param preservation on urls

  • Loading branch information...
commit 11f9546e6021d880a1be80bc03716ddd6bf85c13 1 parent 5bde73a
John Bender authored December 18, 2012
18  js/navigation/path.js
@@ -297,14 +297,14 @@ define([
297 297
 			},
298 298
 
299 299
 			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 ),
303 303
 					preservedHash = uri.hash,
304  
-					cleanedUrl,
305  
-					uiState = "", stateIndex;
  304
+					uiState = "";
306 305
 
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());
308 308
 
309 309
 				// If the url is anything but a simple string, remove any preceding hash
310 310
 				// eg #foo/bar -> foo/bar
@@ -327,6 +327,10 @@ define([
327 327
 				// make the cleanedUrl absolute relative to the resolution url
328 328
 				href = path.makeUrlAbsolute( cleanedUrl, resolutionUrl );
329 329
 
  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
+
330 334
 				// TODO all this crap is terrible, clean it up
331 335
 				if ( isPath ) {
332 336
 					// Get a hash where possible and, as long as it's not a path
@@ -351,7 +355,7 @@ define([
351 355
 
352 356
 					// reconstruct each of the pieces with the new search string and hash
353 357
 					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;
355 359
 				} else {
356 360
 					href += href.indexOf( "#" ) > -1 ? uiState : "#" + uiState;
357 361
 				}
2  tests/unit/path/path_core.js
@@ -288,5 +288,7 @@
288 288
 
289 289
 		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" );
290 290
 
  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
+
291 293
 	});
292 294
 })(jQuery);

0 notes on commit 11f9546

Please sign in to comment.
Something went wrong with that request. Please try again.