LocalRepo: Remove leading 0 from 32-byte SHA1 keys
authorMarko Obrovac <mobrovac@wikimedia.org>
Tue, 3 Sep 2019 13:57:33 +0000 (15:57 +0200)
committerMarko Obrovac <mobrovac@wikimedia.org>
Tue, 3 Sep 2019 14:04:14 +0000 (16:04 +0200)
Bug: T230667
Change-Id: I3d9de7a92495e894b4b44b0a5b0646b6d720f7c2

includes/filerepo/LocalRepo.php
tests/phpunit/includes/filerepo/LocalRepoTest.php

index 5ed937f..8e3355c 100644 (file)
@@ -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;
        }
 
        /**
index bed739b..ab8f2f0 100644 (file)
@@ -136,6 +136,7 @@ class LocalRepoTest extends MediaWikiIntegrationTestCase {
                        [ '.e.x', 'e' ],
                        [ '..f.x', 'f' ],
                        [ 'g..x', 'g' ],
+                       [ '01234567890123456789012345678901.x', '1234567890123456789012345678901' ],
                ];
        }