cvs: php-src /ext/standard strnatcmp.c /ext/standard/tests/array bug44929.phpt

From: Date: Wed, 08 Apr 2009 18:18:49 +0000
Subject: cvs: php-src /ext/standard strnatcmp.c /ext/standard/tests/array bug44929.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-56961@lists.php.net to get a copy of this message
rasmus Wed Apr 8 18:18:49 2009 UTC Modified files: /php-src/ext/standard strnatcmp.c /php-src/ext/standard/tests/array bug44929.phpt Log: Fixed bug #44929 - Better handling of leading zeros 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. http://cvs.php.net/viewvc.cgi/php-src/ext/standard/strnatcmp.c?r1=1.12&r2=1.13&diff_format=u Index: php-src/ext/standard/strnatcmp.c diff -u php-src/ext/standard/strnatcmp.c:1.12 php-src/ext/standard/strnatcmp.c:1.13 --- php-src/ext/standard/strnatcmp.c:1.12 Mon Jan 1 09:29:32 2007 +++ php-src/ext/standard/strnatcmp.c Wed Apr 8 18:18:49 2009 @@ -38,7 +38,7 @@ #if 0 static char const *version UNUSED = - "$Id: strnatcmp.c,v 1.12 2007/01/01 09:29:32 sebastian Exp $"; + "$Id: strnatcmp.c,v 1.13 2009/04/08 18:18:49 rasmus Exp $"; #endif /* {{{ compare_right */ @@ -112,10 +112,10 @@ 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 */ http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/bug44929.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/standard/tests/array/bug44929.phpt diff -u /dev/null php-src/ext/standard/tests/array/bug44929.phpt:1.2 --- /dev/null Wed Apr 8 18:18:49 2009 +++ php-src/ext/standard/tests/array/bug44929.phpt Wed Apr 8 18:18:49 2009 @@ -0,0 +1,31 @@ +--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" +}

« previous php.cvs (#56961) next »