@@ -225,7 +225,7 @@ function pjax(options) {
225225 settings . timeout = 0
226226 }
227227
228- options . requestUrl = parseURL ( settings . url ) . href
228+ options . requestUrl = stripInternalParams ( parseURL ( settings . url ) . href )
229229 }
230230
231231 options . complete = function ( xhr , textStatus ) {
@@ -366,7 +366,7 @@ function pjax(options) {
366366 // Cache current container element before replacing it
367367 cachePush ( pjax . state . id , context . clone ( ) . contents ( ) )
368368
369- window . history . pushState ( null , "" , stripPjaxParam ( options . requestUrl ) )
369+ window . history . pushState ( null , "" , options . requestUrl )
370370 }
371371
372372 fire ( 'pjax:start' , [ xhr , options ] )
@@ -544,16 +544,22 @@ function uniqueId() {
544544 return ( new Date ) . getTime ( )
545545}
546546
547- // Internal: Strips _pjax param from url
547+ // Internal: Strips named query param from url
548548//
549549// url - String
550550//
551551// Returns String.
552- function stripPjaxParam ( url ) {
552+ function stripParam ( url , name ) {
553+ return url
554+ . replace ( new RegExp ( '[?&]' + name + '=[^&]*' ) , '' )
555+ . replace ( / [ ? & ] $ / , '' )
556+ . replace ( / [ ? & ] / , '?' )
557+ }
558+
559+ function stripInternalParams ( url ) {
560+ url = stripParam ( url , '_pjax' )
561+ url = stripParam ( url , '_' )
553562 return url
554- . replace ( / \? _ p j a x = [ ^ & ] + & ? / , '?' )
555- . replace ( / _ p j a x = [ ^ & ] + & ? / , '' )
556- . replace ( / [ \? & ] $ / , '' )
557563}
558564
559565// Internal: Parse URL components and returns a Locationish object.
@@ -669,7 +675,8 @@ function extractContainer(data, xhr, options) {
669675
670676 // Prefer X-PJAX-URL header if it was set, otherwise fallback to
671677 // using the original requested url.
672- obj . url = stripPjaxParam ( xhr . getResponseHeader ( 'X-PJAX-URL' ) || options . requestUrl )
678+ var serverUrl = xhr . getResponseHeader ( 'X-PJAX-URL' )
679+ obj . url = serverUrl ? stripInternalParams ( serverUrl ) : options . requestUrl
673680
674681 // Attempt to parse response html into elements
675682 if ( fullDocument ) {
0 commit comments