From 22bf701fe1b21d883f58fd46c4709315825118ca Mon Sep 17 00:00:00 2001 From: =?utf8?q?Micha=C5=82=20Go=C5=82=C4=99biowski-Owczarek?= Date: Mon, 24 Feb 2020 19:10:03 +0100 Subject: [PATCH] Core:Ajax: Align nonce & global with master, fix an AMD issue This commit aligns the `3.x-stable` branch with `master` in two aspects: 1. It migrates the nonce module to return an object instead of a primitive variable. This had to be changed on `master` as in ES modules you export live read-only bindings to variables, meaning you can't increment the nonce directly. Also, the way it was done so far was working differently in AMD & the single built file - in the built file one nonce variable was declared, accessed and incremented. In AMD mode separate instances were create for each module that depend on the nonce module, creating unintended nonce clashes. 2. Whether the `noGlobal` parameter was set to `true` is now checked using the typeof operator to align with `master`. Closes gh-4612 Ref gh-4541 Ref d0ce00cdfa680f1f0c38460bc51ea14079ae8b07 --- src/ajax.js | 3 ++- src/ajax/jsonp.js | 2 +- src/ajax/var/nonce.js | 2 +- src/exports/global.js | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/ajax.js b/src/ajax.js index 11eda0da0..639a6a380 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -610,7 +610,8 @@ jQuery.extend( { // Add or update anti-cache param if needed if ( s.cache === false ) { cacheURL = cacheURL.replace( rantiCache, "$1" ); - uncached = ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + ( nonce++ ) + uncached; + uncached = ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + ( nonce.guid++ ) + + uncached; } // Put hash and anti-cache on the URL that will be requested (gh-1732) diff --git a/src/ajax/jsonp.js b/src/ajax/jsonp.js index 28ae0365d..10186dea7 100644 --- a/src/ajax/jsonp.js +++ b/src/ajax/jsonp.js @@ -15,7 +15,7 @@ var oldCallbacks = [], jQuery.ajaxSetup( { jsonp: "callback", jsonpCallback: function() { - var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( nonce++ ) ); + var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( nonce.guid++ ) ); this[ callback ] = true; return callback; } diff --git a/src/ajax/var/nonce.js b/src/ajax/var/nonce.js index 33d0cffb6..c0e4472ac 100644 --- a/src/ajax/var/nonce.js +++ b/src/ajax/var/nonce.js @@ -1,5 +1,5 @@ define( function() { "use strict"; - return Date.now(); + return { guid: Date.now() }; } ); diff --git a/src/exports/global.js b/src/exports/global.js index 460b56e47..2cc9577d7 100644 --- a/src/exports/global.js +++ b/src/exports/global.js @@ -1,6 +1,6 @@ define( [ "../core" -], function( jQuery, noGlobal ) { +], function( jQuery ) { "use strict"; @@ -27,7 +27,7 @@ jQuery.noConflict = function( deep ) { // Expose jQuery and $ identifiers, even in AMD // (#7102#comment:10, https://github.com/jquery/jquery/pull/557) // and CommonJS for browser emulators (#13566) -if ( !noGlobal ) { +if ( typeof noGlobal === "undefined" ) { window.jQuery = window.$ = jQuery; } -- 2.39.5