From f65beabcfd0efc7cdb6c826a27175a6e920ed878 Mon Sep 17 00:00:00 2001 From: Marko Obrovac Date: Tue, 3 Sep 2019 15:57:33 +0200 Subject: [PATCH] LocalRepo: Remove leading 0 from 32-byte SHA1 keys Bug: T230667 Change-Id: I3d9de7a92495e894b4b44b0a5b0646b6d720f7c2 --- includes/filerepo/LocalRepo.php | 6 +++++- tests/phpunit/includes/filerepo/LocalRepoTest.php | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/includes/filerepo/LocalRepo.php b/includes/filerepo/LocalRepo.php index 5ed937f581..8e3355c8c6 100644 --- a/includes/filerepo/LocalRepo.php +++ b/includes/filerepo/LocalRepo.php @@ -180,7 +180,11 @@ class LocalRepo extends FileRepo { * @return string */ public static function getHashFromKey( $key ) { - return strtok( $key, '.' ); + $sha1 = strtok( $key, '.' ); + if ( is_string( $sha1 ) && strlen( $sha1 ) === 32 && $sha1[0] === '0' ) { + $sha1 = substr( $sha1, 1 ); + } + return $sha1; } /** diff --git a/tests/phpunit/includes/filerepo/LocalRepoTest.php b/tests/phpunit/includes/filerepo/LocalRepoTest.php index bed739bad9..ab8f2f0442 100644 --- a/tests/phpunit/includes/filerepo/LocalRepoTest.php +++ b/tests/phpunit/includes/filerepo/LocalRepoTest.php @@ -136,6 +136,7 @@ class LocalRepoTest extends MediaWikiIntegrationTestCase { [ '.e.x', 'e' ], [ '..f.x', 'f' ], [ 'g..x', 'g' ], + [ '01234567890123456789012345678901.x', '1234567890123456789012345678901' ], ]; } -- 2.20.1