]> granicus.if.org Git - php/commitdiff
MFB: fix bug #42945
authorNuno Lopes <nlopess@php.net>
Sun, 13 Jan 2008 14:57:54 +0000 (14:57 +0000)
committerNuno Lopes <nlopess@php.net>
Sun, 13 Jan 2008 14:57:54 +0000 (14:57 +0000)
ext/pcre/php_pcre.c
ext/pcre/tests/bug42945.phpt [new file with mode: 0644]

index 0dcd5bbab0826c5d8f4c9e72225e24ea44a02f64..03ae8cc9eff9454fd94a4033ab75e9ea3246e717 100644 (file)
@@ -1747,7 +1747,9 @@ PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, zend_uchar utype, char *s
        }
 
 
-       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..15a3ed6
--- /dev/null
@@ -0,0 +1,162 @@
+--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)
+  }
+}
+--UEXPECT--
+int(2)
+array(1) {
+  [0]=>
+  array(2) {
+    [0]=>
+    array(2) {
+      [0]=>
+      unicode(0) ""
+      [1]=>
+      int(0)
+    }
+    [1]=>
+    array(2) {
+      [0]=>
+      unicode(0) ""
+      [1]=>
+      int(1)
+    }
+  }
+}
+array(3) {
+  [0]=>
+  unicode(0) ""
+  [1]=>
+  unicode(1) "a"
+  [2]=>
+  unicode(1) "'"
+}
+array(3) {
+  [0]=>
+  array(2) {
+    [0]=>
+    unicode(0) ""
+    [1]=>
+    int(0)
+  }
+  [1]=>
+  array(2) {
+    [0]=>
+    unicode(1) "a"
+    [1]=>
+    int(0)
+  }
+  [2]=>
+  array(2) {
+    [0]=>
+    unicode(1) "'"
+    [1]=>
+    int(1)
+  }
+}
+array(2) {
+  [0]=>
+  unicode(1) "a"
+  [1]=>
+  unicode(1) "'"
+}
+array(2) {
+  [0]=>
+  array(2) {
+    [0]=>
+    unicode(1) "a"
+    [1]=>
+    int(0)
+  }
+  [1]=>
+  array(2) {
+    [0]=>
+    unicode(1) "'"
+    [1]=>
+    int(1)
+  }
+}