From f2383b216efad6a9e19492c6cae41911163528f0 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Sun, 16 Dec 2012 17:45:31 -0500 Subject: [PATCH] (bug 43177) API: Fix regression in case handling for sha1 params 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 | 7 ++++--- includes/api/ApiQueryFilearchive.php | 9 +++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/includes/api/ApiQueryAllImages.php b/includes/api/ApiQueryAllImages.php index e6a0194607..2319263dcf 100644 --- a/includes/api/ApiQueryAllImages.php +++ b/includes/api/ApiQueryAllImages.php @@ -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' ); } diff --git a/includes/api/ApiQueryFilearchive.php b/includes/api/ApiQueryFilearchive.php index dbca1d96db..7ec47fa91f 100644 --- a/includes/api/ApiQueryFilearchive.php +++ b/includes/api/ApiQueryFilearchive.php @@ -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 ); -- 2.20.1