From: Bartosz DziewoƄski Date: Fri, 3 Mar 2017 20:43:58 +0000 (+0100) Subject: mw.special.apisandbox: Correct fixTokenAndResend() when a token is already known X-Git-Tag: 1.31.0-rc.0~3901 X-Git-Url: https://git.cyclocoop.org/admin/?a=commitdiff_plain;h=716d331f29587eaa5d86de43f9fe098d360af88e;p=lhc%2Fweb%2Fwiklou.git mw.special.apisandbox: Correct fixTokenAndResend() when a token is already known In this snippet: success = function ( k ) { delete tokenWait[ k ]; ... }; ... tokenWait[ k ] = page.tokenWidget.fetchToken() .done( success.bind( page.tokenWidget, k ) ) .fail( failure.bind( page.tokenWidget, k ) ); If fetchToken() returns a promise that is already resolved (because we have the token cached), the `delete tokenWait[ k ];` will happen before the `tokenWait[ k ] = ...`, and later code checking that `tokenWait` is empty will not work correctly. Fix this by doing the assigment before connecting the done/fail handlers, in a separate statement. Change-Id: Ieeb23cad0fd7e0cd4d3d259ff9f324f2001de0c6 --- diff --git a/resources/src/mediawiki.special/mediawiki.special.apisandbox.js b/resources/src/mediawiki.special/mediawiki.special.apisandbox.js index 7687fd8e5c..97659edca3 100644 --- a/resources/src/mediawiki.special/mediawiki.special.apisandbox.js +++ b/resources/src/mediawiki.special/mediawiki.special.apisandbox.js @@ -1218,7 +1218,8 @@ if ( page.tokenWidget ) { k = page.apiModule + page.tokenWidget.paramInfo.name; - tokenWait[ k ] = page.tokenWidget.fetchToken() + tokenWait[ k ] = page.tokenWidget.fetchToken(); + tokenWait[ k ] .done( success.bind( page.tokenWidget, k ) ) .fail( failure.bind( page.tokenWidget, k ) ); }