]> granicus.if.org Git - php/commitdiff
MFH: fix explode behavior to respect negative limit when string is empty.
authorBrian Shire <shire@php.net>
Sat, 27 Dec 2008 05:20:27 +0000 (05:20 +0000)
committerBrian Shire <shire@php.net>
Sat, 27 Dec 2008 05:20:27 +0000 (05:20 +0000)
NEWS
ext/standard/string.c
ext/standard/tests/strings/explode.phpt

diff --git a/NEWS b/NEWS
index 3cfd09e25cf96c9334c3bf09269326d7648a9068..8516130bec86693a3f366792d7554196e0d48d6b 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,7 @@
 PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 2009, PHP 5.2.9
+- Fixed explode() behavior to respect negative limit when string is empty. (shire)
 - Added optional sorting type flag parameter to array_unique(), default is
   SORT_REGULAR. (Andrei)
 - Fixed security issue in imagerotate(), background colour isn't validated
index 94b05a88e361bca10f9eb5660fd3c6199049f7b9..0b648c924b673db3746b8883d351cb9e8ccfb4c4 100644 (file)
@@ -1033,7 +1033,9 @@ PHP_FUNCTION(explode)
        array_init(return_value);
 
        if (! Z_STRLEN_PP(str)) {
-               add_next_index_stringl(return_value, "", sizeof("") - 1, 1);
+               if (limit >= 0 || argc == 2) {
+                       add_next_index_stringl(return_value, "", sizeof("") - 1, 1);
+               } 
                return;
        }
 
index 6d54b6609042e94fdf1658ae42906256e4abab8b..1047fb7856295ec28f399c23f8397edf19cd5e23 100644 (file)
@@ -17,6 +17,7 @@ var_dump(@explode("a", NULL));
 var_dump(@explode(NULL, a));
 var_dump(@explode("abc", "acb"));
 var_dump(@explode("somestring", "otherstring"));
+var_dump(@explode("somestring", "otherstring", -1));
 var_dump(@explode("a", "aaaaaa"));
 var_dump(@explode("==", str_repeat("-=".ord(0)."=-", 10)));
 var_dump(@explode("=", str_repeat("-=".ord(0)."=-", 10)));
@@ -63,6 +64,8 @@ array(1) {
   [0]=>
   string(11) "otherstring"
 }
+array(0) {
+}
 array(7) {
   [0]=>
   string(0) ""