(bug 43177) API: Fix regression in case handling for sha1 params
authorBrad Jorsch <bjorsch@wikimedia.org>
Sun, 16 Dec 2012 22:45:31 +0000 (17:45 -0500)
committerBrad Jorsch <bjorsch@wikimedia.org>
Mon, 17 Dec 2012 14:30:12 +0000 (09:30 -0500)
While the change in Ic980fd71 makes sense since MediaWiki stores the
hashes with lowercase letters, historically aisha1 and fasha1 accepted
both upper and lowercase because wfBaseConvert accepts both.

To avoid a backwards compatibility break, let's adjust the code to
explicitly lowercase the input for those parameters. And for good
measure, let's also accept both cases for the corresponding sha1base36
parameters.

Change-Id: I704935193398c722c22a302dc9d23f2c0e2e3e39

includes/api/ApiQueryAllImages.php
includes/api/ApiQueryFilearchive.php

index e6a0194..2319263 100644 (file)
@@ -175,12 +175,13 @@ class ApiQueryAllImages extends ApiQueryGeneratorBase {
 
                $sha1 = false;
                if ( isset( $params['sha1'] ) ) {
-                       if ( !$this->validateSha1Hash( $params['sha1'] ) ) {
+                       $sha1 = strtolower( $params['sha1'] );
+                       if ( !$this->validateSha1Hash( $sha1 ) ) {
                                $this->dieUsage( 'The SHA1 hash provided is not valid', 'invalidsha1hash' );
                        }
-                       $sha1 = wfBaseConvert( $params['sha1'], 16, 36, 31 );
+                       $sha1 = wfBaseConvert( $sha1, 16, 36, 31 );
                } elseif ( isset( $params['sha1base36'] ) ) {
-                       $sha1 = $params['sha1base36'];
+                       $sha1 = strtolower( $params['sha1base36'] );
                        if ( !$this->validateSha1Base36Hash( $sha1 ) ) {
                                $this->dieUsage( 'The SHA1Base36 hash provided is not valid', 'invalidsha1base36hash' );
                        }
index dbca1d9..7ec47fa 100644 (file)
@@ -103,15 +103,16 @@ class ApiQueryFilearchive extends ApiQueryBase {
                if ( $sha1Set || $sha1base36Set ) {
                        $sha1 = false;
                        if ( $sha1Set ) {
-                               if ( !$this->validateSha1Hash( $params['sha1'] ) ) {
+                               $sha1 = strtolower( $params['sha1'] );
+                               if ( !$this->validateSha1Hash( $sha1 ) ) {
                                        $this->dieUsage( 'The SHA1 hash provided is not valid', 'invalidsha1hash' );
                                }
-                               $sha1 = wfBaseConvert( $params['sha1'], 16, 36, 31 );
+                               $sha1 = wfBaseConvert( $sha1, 16, 36, 31 );
                        } elseif ( $sha1base36Set ) {
-                               if ( !$this->validateSha1Base36Hash( $params['sha1base36'] ) ) {
+                               $sha1 = strtolower( $params['sha1base36'] );
+                               if ( !$this->validateSha1Base36Hash( $sha1 ) ) {
                                        $this->dieUsage( 'The SHA1Base36 hash provided is not valid', 'invalidsha1base36hash' );
                                }
-                               $sha1 = $params['sha1base36'];
                        }
                        if ( $sha1 ) {
                                $this->addWhereFld( 'fa_sha1', $sha1 );