This is obviously not going to work for Unicode strings, but the whole
function needs to be rewritten, so keep it in synch with the other
branches for now.
ca = a[ai]; cb = b[bi];
/* skip over leading spaces or zeros */
- while (isspace((int)(unsigned char)ca))
+ while (isspace((int)(unsigned char)ca) || (ca == '0' && ap+1 < aend))
ca = a[++ai];
- while (isspace((int)(unsigned char)cb))
+ while (isspace((int)(unsigned char)cb) || (cb == '0' && bp+1 < bend))
cb = b[++bi];
/* process run of digits */
--- /dev/null
+--TEST--
+Bug #44929 (natsort doesn't handle leading zeros well)
+--FILE--
+<?php
+$a = array('001','008','005','00011','03','000014','-123','0.002','00','0');
+natsort($a);
+var_dump($a);
+?>
+--EXPECT--
+array(10) {
+ [6]=>
+ string(4) "-123"
+ [7]=>
+ string(5) "0.002"
+ [8]=>
+ string(2) "00"
+ [9]=>
+ string(1) "0"
+ [0]=>
+ string(3) "001"
+ [4]=>
+ string(2) "03"
+ [2]=>
+ string(3) "005"
+ [1]=>
+ string(3) "008"
+ [3]=>
+ string(5) "00011"
+ [5]=>
+ string(6) "000014"
+}