From 0c51e9d55f39366cab14719b80cb7e989c716351 Mon Sep 17 00:00:00 2001 From: jaubourg Date: Wed, 12 Jan 2011 18:36:00 +0100 Subject: [PATCH] Fixes #4897. Added ?? as a context-insensitive placeholder for the callback name of a JSONP request. Unit tests provided. --- src/ajax/jsonp.js | 6 ++--- test/data/jsonp.php | 4 ++++ test/unit/ajax.js | 57 +++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 62 insertions(+), 5 deletions(-) diff --git a/src/ajax/jsonp.js b/src/ajax/jsonp.js index f4b324e1..dd04b34b 100644 --- a/src/ajax/jsonp.js +++ b/src/ajax/jsonp.js @@ -1,7 +1,7 @@ (function( jQuery ) { var jsc = jQuery.now(), - jsre = /\=(?:\?|%3F)(&|$)/i, + jsre = /(\=)(?:\?|%3F)(&|$)|()(?:\?\?|%3F%3F)()/i, rquery_jsonp = /\?/; // Default jsonp settings @@ -25,8 +25,8 @@ jQuery.ajax.prefilter("json jsonp", function(s, originalSettings) { var jsonpCallback = s.jsonpCallback = jQuery.isFunction( s.jsonpCallback ) ? s.jsonpCallback() : s.jsonpCallback, - url = s.url.replace(jsre, "=" + jsonpCallback + "$1"), - data = s.url === url && typeof(s.data) === "string" ? s.data.replace(jsre, "=" + jsonpCallback + "$1") : s.data; + url = s.url.replace(jsre, "$1" + jsonpCallback + "$2"), + data = s.url === url && typeof(s.data) === "string" ? s.data.replace(jsre, "$1" + jsonpCallback + "$2") : s.data; if ( url === s.url && data === s.data ) { url += (rquery_jsonp.test( url ) ? "&" : "?") + s.jsonp + "=" + jsonpCallback; diff --git a/test/data/jsonp.php b/test/data/jsonp.php index 9ae1d848..6c13d72e 100644 --- a/test/data/jsonp.php +++ b/test/data/jsonp.php @@ -1,6 +1,10 @@