ID: 44929
Updated by: [EMAIL PROTECTED]
Reported By: kae at verens dot com
-Status: Open
+Status: Assigned
Bug Type: Arrays related
Operating System: Linux
PHP Version: 5.2.6
-Assigned To:
+Assigned To: rasmus
New Comment:
Rasmus, why don't you commit the patch if it fixes this..?
Previous Comments:
------------------------------------------------------------------------
[2008-05-07 18:35:04] [EMAIL PROTECTED]
This should fix this one:
Index: strnatcmp.c
===================================================================
RCS file: /repository/php-src/ext/standard/strnatcmp.c,v
retrieving revision 1.10
diff -u -1 -r1.10 strnatcmp.c
--- strnatcmp.c 15 Jul 2004 01:26:03 -0000 1.10
+++ strnatcmp.c 7 May 2008 18:34:31 -0000
@@ -118,6 +118,6 @@
/* skip over leading spaces or zeros */
- while (isspace((int)(unsigned char)ca))
+ while (isspace((int)(unsigned char)ca) || ca=='0')
ca = *++ap;
- while (isspace((int)(unsigned char)cb))
+ while (isspace((int)(unsigned char)cb) || cb=='0')
cb = *++bp;
------------------------------------------------------------------------
[2008-05-07 15:38:51] kae at verens dot com
I'm sorry - I think I misunderstand something here.
I have just tried with the example values in
http://sourcefrog.net/projects/natsort/example-out.txt
Expected result: no change from the input array to the outputted
array.
Actual result: the input array order is incorrect where values have a
'0' in front of them
Sample code:
<?php
$arr=array(
'1-2', '1-02', '1-20', '10-20',
'fred', 'jane', 'pic01', 'pic2',
'pic02', 'pic02a', 'pic3', 'pic4',
'pic 4 else', 'pic 5', 'pic05', 'pic 5 ',
'pic 5 something', 'pic 6', 'pic 7', 'pic100',
'pic100a', 'pic120', 'pic121', 'pic02000',
'tom', 'x2-g8', 'x2-y7', 'x2-y08',
'x8-y8'
);
natsort($arr);
var_dump($arr);
note that the values in the array there are /already sorted/ according
to natsort. With that in mind, the output should match the input.
Actual result:
array
1 => string '1-02' (length=4)
0 => string '1-2' (length=3)
2 => string '1-20' (length=4)
3 => string '10-20' (length=5)
4 => string 'fred' (length=4)
5 => string 'jane' (length=4)
6 => string 'pic01' (length=5)
8 => string 'pic02' (length=5)
9 => string 'pic02a' (length=6)
23 => string 'pic02000' (length=8)
14 => string 'pic05' (length=5)
7 => string 'pic2' (length=4)
10 => string 'pic3' (length=4)
11 => string 'pic4' (length=4)
12 => string 'pic 4 else' (length=10)
13 => string 'pic 5' (length=5)
15 => string 'pic 5 ' (length=6)
16 => string 'pic 5 something' (length=15)
17 => string 'pic 6' (length=5)
18 => string 'pic 7' (length=7)
19 => string 'pic100' (length=6)
20 => string 'pic100a' (length=7)
21 => string 'pic120' (length=6)
22 => string 'pic121' (length=6)
24 => string 'tom' (length=3)
25 => string 'x2-g8' (length=5)
27 => string 'x2-y08' (length=6)
26 => string 'x2-y7' (length=5)
28 => string 'x8-y8' (length=5)
------------------------------------------------------------------------
[2008-05-06 14:32:32] kae at verens dot com
Description:
------------
natsort, which sorts arrays using natural language, does not understand
numbers which begin with '0'.
Reproduce code:
---------------
<?php
$arr= array('test012','test01','test02');
natsort($arr);
var_dump($arr);
Expected result:
----------------
array
1 => string 'test01' (length=6)
2 => string 'test02' (length=6)
0 => string 'test012' (length=7)
Actual result:
--------------
array
1 => string 'test01' (length=6)
0 => string 'test012' (length=7)
2 => string 'test02' (length=6)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=44929&edit=1