Before php/php-src@
834daa455bc9, PHP's gmp_init() function would try
to autodetect hex and binary numbers even when a base was explicitly
specified[1], so the results for some base-36 numbers having leading
zeros could be incorrect. Work around this bug by trimming off any
leading zeros before calling gmp_init().
[1]: https://bugs.php.net/bug.php?id=50175
Bug: 69249
Change-Id: I5f5458c1a1195f55fa12904c103da6ea7558010a
* (bugs 57238, 65206) Blank pages can now be directly created.
* (bug 69789) Title::getContentModel() now loads from the database when
necessary instead of incorrectly returning the default content model.
+* (bug 69249) wfBaseConvert() now works around PHP Bug #50175 when using GMP.
=== Action API changes in 1.24 ===
* action=parse API now supports prop=modules, which provides the list of
);
if ( extension_loaded( 'gmp' ) && ( $engine == 'auto' || $engine == 'gmp' ) ) {
- $result = gmp_strval( gmp_init( $input, $sourceBase ), $destBase );
+ // Removing leading zeros works around broken base detection code in
+ // some PHP versions (see <https://bugs.php.net/bug.php?id=50175> and
+ // <https://bugs.php.net/bug.php?id=55398>).
+ $result = gmp_strval( gmp_init( ltrim( $input, '0' ), $sourceBase ), $destBase );
} elseif ( extension_loaded( 'bcmath' ) && ( $engine == 'auto' || $engine == 'bcmath' ) ) {
$decimal = '0';
foreach ( str_split( strtolower( $input ) ) as $char ) {
strlen( wfBaseConvert( $number, 2, 2, strlen( $number ) - 5 ) )
);
}
+
+ public function testLeadingZero() {
+ $this->assertSame( '24', wfBaseConvert( '010', 36, 16 ) );
+ $this->assertSame( '37d4', wfBaseConvert( '0b10', 36, 16 ) );
+ $this->assertSame( 'a734', wfBaseConvert( '0x10', 36, 16 ) );
+ }
}