From 452f71b63c34bc807d565c24cfe5881804a05f07 Mon Sep 17 00:00:00 2001 From: Rasmus Lerdorf Date: Wed, 8 Apr 2009 18:18:49 +0000 Subject: [PATCH] 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. --- ext/standard/strnatcmp.c | 4 ++-- ext/standard/tests/array/bug44929.phpt | 31 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 ext/standard/tests/array/bug44929.phpt diff --git a/ext/standard/strnatcmp.c b/ext/standard/strnatcmp.c index 39ab9a49c7..5b05c65299 100644 --- a/ext/standard/strnatcmp.c +++ b/ext/standard/strnatcmp.c @@ -112,10 +112,10 @@ PHPAPI int strnatcmp_ex(char const *a, size_t a_len, char const *b, size_t b_len 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 */ diff --git a/ext/standard/tests/array/bug44929.phpt b/ext/standard/tests/array/bug44929.phpt new file mode 100644 index 0000000000..ae71e06cff --- /dev/null +++ b/ext/standard/tests/array/bug44929.phpt @@ -0,0 +1,31 @@ +--TEST-- +Bug #44929 (natsort doesn't handle leading zeros well) +--FILE-- + +--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" +} -- 2.50.1