]> granicus.if.org Git - php/commitdiff
Fixed bug #42945 (preg_split() swallows part of the string)
authorNuno Lopes <nlopess@php.net>
Sun, 13 Jan 2008 14:44:29 +0000 (14:44 +0000)
committerNuno Lopes <nlopess@php.net>
Sun, 13 Jan 2008 14:44:29 +0000 (14:44 +0000)
NEWS
ext/pcre/php_pcre.c
ext/pcre/tests/bug42945.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 003972221525fa40c8d50219410ce8cfb3c79ff8..8ba0a2a2a6e0e05b0d09e1b94ca7b42f6b2c9d35 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -71,6 +71,7 @@ PHP                                                                        NEWS
 - Fixed bug #43128 (Very long class name causes segfault). (Dmitry)
 - Fixed bug #42952 (soap cache file is created with insecure permissions).
   (Dmitry)
+- Fixed bug #42945 (preg_split() swallows part of the string). (Nuno)
 - Fixed bug #42868 (Floats cast to integer produce unpredictable results).
   (Zoe Slattery)
 - Fixed bug #42848 (Status: header incorrect under FastCGI). (Dmitry)
index 9e2187d649e79639eee414f97bb3405d1b31d810..07abff432f36c5244e4e25356644ed4b1952373e 100644 (file)
@@ -1562,7 +1562,9 @@ PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, char *subject, int subjec
        }
 
 
-       if (!no_empty || start_offset != subject_len)
+       start_offset = last_match - subject; /* the offset might have been incremented, but without further successful matches */
+
+       if (!no_empty || start_offset < subject_len)
        {
                if (offset_capture) {
                        /* Add the last (match, offset) pair to the return value */
diff --git a/ext/pcre/tests/bug42945.phpt b/ext/pcre/tests/bug42945.phpt
new file mode 100644 (file)
index 0000000..c6d2b82
--- /dev/null
@@ -0,0 +1,88 @@
+--TEST--
+Bug #42945 (preg_split() swallows part of the string)
+--FILE--
+<?php
+
+var_dump(preg_match_all('/\b/', "a'", $m, PREG_OFFSET_CAPTURE));
+var_dump($m);
+
+var_dump(preg_split('/\b/', "a'"));
+var_dump(preg_split('/\b/', "a'", -1, PREG_SPLIT_OFFSET_CAPTURE));
+var_dump(preg_split('/\b/', "a'", -1, PREG_SPLIT_NO_EMPTY));
+var_dump(preg_split('/\b/', "a'", -1, PREG_SPLIT_NO_EMPTY|PREG_SPLIT_OFFSET_CAPTURE));
+
+?>
+--EXPECT--
+int(2)
+array(1) {
+  [0]=>
+  array(2) {
+    [0]=>
+    array(2) {
+      [0]=>
+      string(0) ""
+      [1]=>
+      int(0)
+    }
+    [1]=>
+    array(2) {
+      [0]=>
+      string(0) ""
+      [1]=>
+      int(1)
+    }
+  }
+}
+array(3) {
+  [0]=>
+  string(0) ""
+  [1]=>
+  string(1) "a"
+  [2]=>
+  string(1) "'"
+}
+array(3) {
+  [0]=>
+  array(2) {
+    [0]=>
+    string(0) ""
+    [1]=>
+    int(0)
+  }
+  [1]=>
+  array(2) {
+    [0]=>
+    string(1) "a"
+    [1]=>
+    int(0)
+  }
+  [2]=>
+  array(2) {
+    [0]=>
+    string(1) "'"
+    [1]=>
+    int(1)
+  }
+}
+array(2) {
+  [0]=>
+  string(1) "a"
+  [1]=>
+  string(1) "'"
+}
+array(2) {
+  [0]=>
+  array(2) {
+    [0]=>
+    string(1) "a"
+    [1]=>
+    int(0)
+  }
+  [1]=>
+  array(2) {
+    [0]=>
+    string(1) "'"
+    [1]=>
+    int(1)
+  }
+}