|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-07-09 17:23 UTC] oliver at burtchen dot com
Description:
------------
strnatcmp('foo ', 'foo ') returns -1 and not 0 as expected. As far as I can see, it depends on the trailling whitespace.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 04:00:01 2025 UTC |
The problem is that spaces at the end of the string cause the ap and bp pointers to be looking at strlen+1 here is the patch to prevent that. Index: ext/standard/strnatcmp.c =================================================================== RCS file: /repository/php-src/ext/standard/strnatcmp.c,v retrieving revision 1.9 diff -u -r1.9 strnatcmp.c --- ext/standard/strnatcmp.c 16 Apr 2003 21:10:29 -0000 1.9 +++ ext/standard/strnatcmp.c 11 Jul 2004 20:38:30 -0000 @@ -153,13 +153,13 @@ return +1; ++ap; ++bp; - if (ap == aend && bp == bend) + if (ap >= aend && bp >= bend) /* The strings compare the same. Perhaps the caller will want to call strcmp to break the tie. */ return 0; - else if (ap == aend) + else if (ap >= aend) return -1; - else if (bp == bend) + else if (bp >= bend) return 1; } }