@@ -41,19 +41,34 @@ define([
4141 urlParseRE : / ^ \s * ( ( ( ( [ ^ : \/ # \? ] + : ) ? (?: ( \/ \/ ) ( (?: ( ( [ ^ : @ \/ # \? ] + ) (?: \: ( [ ^ : @ \/ # \? ] + ) ) ? ) @ ) ? ( ( [ ^ : \/ # \? \] \[ ] + | \[ [ ^ \/ \] @ # ? ] + \] ) (?: \: ( [ 0 - 9 ] + ) ) ? ) ) ? ) ? ) ? ( ( \/ ? (?: [ ^ \/ \? # ] + \/ + ) * ) ( [ ^ \? # ] * ) ) ) ? ( \? [ ^ # ] + ) ? ) ( # .* ) ? / ,
4242
4343 // Abstraction to address xss (Issue #4787) by removing the authority in
44- // browsers that auto decode it. All references to location.href should be
44+ // browsers that auto- decode it. All references to location.href should be
4545 // replaced with a call to this method so that it can be dealt with properly here
4646 getLocation : function ( url ) {
47- var uri = url ? this . parseUrl ( url ) : location ,
48- hash = this . parseUrl ( url || location . href ) . hash ;
47+ var parsedUrl = this . parseUrl ( url || location . href ) ,
48+ uri = url ? parsedUrl : location ,
49+
50+ // Make sure to parse the url or the location object for the hash because using
51+ // location.hash is autodecoded in firefox, the rest of the url should be from
52+ // the object (location unless we're testing) to avoid the inclusion of the
53+ // authority
54+ hash = parsedUrl . hash ;
4955
5056 // mimic the browser with an empty string when the hash is empty
5157 hash = hash === "#" ? "" : hash ;
5258
53- // Make sure to parse the url or the location object for the hash because using location.hash
54- // is autodecoded in firefox, the rest of the url should be from the object (location unless
55- // we're testing) to avoid the inclusion of the authority
56- return uri . protocol + "//" + uri . host + uri . pathname + uri . search + hash ;
59+ return uri . protocol +
60+ parsedUrl . doubleSlash +
61+ uri . host +
62+
63+ // The pathname must start with a slash if there's a protocol, because you
64+ // can't have a protocol followed by a relative path. Also, it's impossible to
65+ // calculate absolute URLs from relative ones if the absolute one doesn't have
66+ // a leading "/".
67+ ( ( uri . protocol !== "" && uri . pathname . substring ( 0 , 1 ) !== "/" ) ?
68+ "/" : "" ) +
69+ uri . pathname +
70+ uri . search +
71+ hash ;
5772 } ,
5873
5974 //return the original document url
@@ -323,7 +338,8 @@ define([
323338
324339 // reconstruct each of the pieces with the new search string and hash
325340 href = path . parseUrl ( href ) ;
326- href = href . protocol + "//" + href . host + href . pathname + search + preservedHash ;
341+ href = href . protocol + href . doubleSlash + href . host + href . pathname + search +
342+ preservedHash ;
327343 } else {
328344 href += href . indexOf ( "#" ) > - 1 ? uiState : "#" + uiState ;
329345 }
0 commit comments