jenkins-bot has submitted this change and it was merged.

Change subject: Clean up a bit of Amazon javascript
......................................................................


Clean up a bit of Amazon javascript

Fix URL parameter retrieval function, clarify token validation.

Bug: T108112
Change-Id: I3b614c1aef2a254d4b8164ff08ef05815b31ac53
---
M amazon_gateway/amazon.js
1 file changed, 11 insertions(+), 8 deletions(-)

Approvals:
  Awight: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/amazon_gateway/amazon.js b/amazon_gateway/amazon.js
index 7eaefed..358801d 100644
--- a/amazon_gateway/amazon.js
+++ b/amazon_gateway/amazon.js
@@ -9,23 +9,25 @@
                loggedIn = false,
                loginError,
                accessToken,
+               validTokenPattern = new RegExp( '^Atza' ),
                billingAgreementId,
                orderReferenceId;
 
-       // Cribbed from Amazon documentation
+       // Adapted from Amazon documentation
        function getURLParameter( name, source ) {
-               return decodeURIComponent( (
-                       new RegExp( '[?|&|#]' + name + '=' + 
'([^&;]+?)(&|#|;|$)' ).exec( source )
-                       || [,""]
-               )[1].replace( /\+/g, '%20' ) ) || null;
+               var pattern = '[?&#]' + name + '=' + '([^&;#]*)',
+                       matches = new RegExp( pattern ).exec( source ) || ['', 
''],
+                       value = matches[1].replace( /\+/g, '%20' );
+
+               return decodeURIComponent( value ) || null;
        }
 
        function loadScript( url ) {
-               var a = document.createElement('script');
+               var a = document.createElement( 'script' );
                a.type = 'text/javascript';
                a.async = true;
                a.src = url;
-               document.head.appendChild(a);
+               document.head.appendChild( a );
        }
 
        function redirectToLogin() {
@@ -75,7 +77,8 @@
                }
        };
 
-       if ( typeof accessToken === 'string' && accessToken.match( /^Atza/ ) ) {
+       if ( typeof accessToken === 'string' && accessToken.match( 
validTokenPattern ) ) {
+               // Payment widgets need this cookie
                document.cookie = "amazon_Login_accessToken=" + accessToken + 
";secure";
                loggedIn = true;
                loadScript( widgetScript ); // This will load the login script 
for you

-- 
To view, visit https://gerrit.wikimedia.org/r/231794
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I3b614c1aef2a254d4b8164ff08ef05815b31ac53
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: amazon
Gerrit-Owner: Ejegg <[email protected]>
Gerrit-Reviewer: AndyRussG <[email protected]>
Gerrit-Reviewer: Awight <[email protected]>
Gerrit-Reviewer: Ssmith <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to