mw.special.apisandbox: Correct fixTokenAndResend() when a token is already known
authorBartosz Dziewoński <matma.rex@gmail.com>
Fri, 3 Mar 2017 20:43:58 +0000 (21:43 +0100)
committerBartosz Dziewoński <matma.rex@gmail.com>
Fri, 3 Mar 2017 22:17:58 +0000 (22:17 +0000)
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

resources/src/mediawiki.special/mediawiki.special.apisandbox.js

index 7687fd8..97659ed 100644 (file)
 
                                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 ) );
                                }