mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Ajax: Don't mangle the URL when removing the anti-cache param
Fixes gh-3229 Closes gh-3253
This commit is contained in:
parent
9526557e67
commit
cd4ad00478
@ -18,7 +18,7 @@ define( [
|
|||||||
var
|
var
|
||||||
r20 = /%20/g,
|
r20 = /%20/g,
|
||||||
rhash = /#.*$/,
|
rhash = /#.*$/,
|
||||||
rts = /([?&])_=[^&]*/,
|
rantiCache = /([?&])_=[^&]*/,
|
||||||
rheaders = /^(.*?):[ \t]*([^\r\n]*)$/mg,
|
rheaders = /^(.*?):[ \t]*([^\r\n]*)$/mg,
|
||||||
|
|
||||||
// #7653, #8125, #8152: local protocol detection
|
// #7653, #8125, #8152: local protocol detection
|
||||||
@ -604,9 +604,9 @@ jQuery.extend( {
|
|||||||
delete s.data;
|
delete s.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add anti-cache in uncached url if needed
|
// Add or update anti-cache param if needed
|
||||||
if ( s.cache === false ) {
|
if ( s.cache === false ) {
|
||||||
cacheURL = cacheURL.replace( rts, "" );
|
cacheURL = cacheURL.replace( rantiCache, "$1" );
|
||||||
uncached = ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + ( nonce++ ) + uncached;
|
uncached = ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + ( nonce++ ) + uncached;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -828,8 +828,9 @@ QUnit.module( "ajax", {
|
|||||||
} ), "generic" );
|
} ), "generic" );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
ajaxTest( "jQuery.ajax() - cache", 12, function( assert ) {
|
ajaxTest( "jQuery.ajax() - cache", 28, function( assert ) {
|
||||||
var re = /_=(.*?)(&|$)/g;
|
var re = /_=(.*?)(&|$)/g,
|
||||||
|
rootUrl = "data/text.php";
|
||||||
|
|
||||||
function request( url, title ) {
|
function request( url, title ) {
|
||||||
return {
|
return {
|
||||||
@ -837,6 +838,11 @@ QUnit.module( "ajax", {
|
|||||||
cache: false,
|
cache: false,
|
||||||
beforeSend: function() {
|
beforeSend: function() {
|
||||||
var parameter, tmp;
|
var parameter, tmp;
|
||||||
|
|
||||||
|
// URL sanity check
|
||||||
|
assert.equal( this.url.indexOf( rootUrl ), 0, "root url not mangled: " + this.url );
|
||||||
|
assert.equal( /\&.*\?/.test( this.url ), false, "parameter delimiters in order" );
|
||||||
|
|
||||||
while ( ( tmp = re.exec( this.url ) ) ) {
|
while ( ( tmp = re.exec( this.url ) ) ) {
|
||||||
assert.strictEqual( parameter, undefined, title + ": only one 'no-cache' parameter" );
|
assert.strictEqual( parameter, undefined, title + ": only one 'no-cache' parameter" );
|
||||||
parameter = tmp[ 1 ];
|
parameter = tmp[ 1 ];
|
||||||
@ -850,27 +856,31 @@ QUnit.module( "ajax", {
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
request(
|
request(
|
||||||
"data/text.php",
|
rootUrl,
|
||||||
"no parameter"
|
"no query"
|
||||||
),
|
),
|
||||||
request(
|
request(
|
||||||
"data/text.php?pizza=true",
|
rootUrl + "?",
|
||||||
|
"empty query"
|
||||||
|
),
|
||||||
|
request(
|
||||||
|
rootUrl + "?pizza=true",
|
||||||
"1 parameter"
|
"1 parameter"
|
||||||
),
|
),
|
||||||
request(
|
request(
|
||||||
"data/text.php?_=tobereplaced555",
|
rootUrl + "?_=tobereplaced555",
|
||||||
"_= parameter"
|
"_= parameter"
|
||||||
),
|
),
|
||||||
request(
|
request(
|
||||||
"data/text.php?pizza=true&_=tobereplaced555",
|
rootUrl + "?pizza=true&_=tobereplaced555",
|
||||||
"1 parameter and _="
|
"1 parameter and _="
|
||||||
),
|
),
|
||||||
request(
|
request(
|
||||||
"data/text.php?_=tobereplaced555&tv=false",
|
rootUrl + "?_=tobereplaced555&tv=false",
|
||||||
"_= and 1 parameter"
|
"_= and 1 parameter"
|
||||||
),
|
),
|
||||||
request(
|
request(
|
||||||
"data/text.php?name=David&_=tobereplaced555&washere=true",
|
rootUrl + "?name=David&_=tobereplaced555&washere=true",
|
||||||
"2 parameters surrounding _="
|
"2 parameters surrounding _="
|
||||||
)
|
)
|
||||||
];
|
];
|
||||||
|
Loading…
Reference in New Issue
Block a user