From: Kaldari Date: Thu, 20 Oct 2016 18:56:54 +0000 (-0700) Subject: Fixing numeric sorting for numbers with leading zeros X-Git-Tag: 1.31.0-rc.0~5062^2 X-Git-Url: http://git.cyclocoop.org//%22%24path/mw-config/index.%24ext/%22?a=commitdiff_plain;h=3c8490b1e3206e88bd3b6491ebb0360ea01a98f8;p=lhc%2Fweb%2Fwiklou.git Fixing numeric sorting for numbers with leading zeros Bug: T148774 Change-Id: I34aa330645d9d82b6c4e57542e891dd2b36e42ad --- diff --git a/includes/collation/NumericUppercaseCollation.php b/includes/collation/NumericUppercaseCollation.php index 4bf2f737fb..d15daec505 100644 --- a/includes/collation/NumericUppercaseCollation.php +++ b/includes/collation/NumericUppercaseCollation.php @@ -36,11 +36,13 @@ class NumericUppercaseCollation extends UppercaseCollation { // shorter numbers before longer ones; if identical, then the characters will be compared, which // generates the correct results for numbers of equal length. $sortkey = preg_replace_callback( '/\d+/', function ( $matches ) { - $len = strlen( $matches[0] ); + // Strip any leading zeros + $number = ltrim( $matches[0], '0' ); + $len = strlen( $number ); // This allows sequences of up to 65536 numeric characters to be handled correctly. One byte // would allow only for 256, which doesn't feel future-proof. $prefix = chr( floor( $len / 256 ) ) . chr( $len % 256 ); - return '0' . $prefix . $matches[0]; + return '0' . $prefix . $number; }, $sortkey ); return $sortkey;