summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNuno Lopes <nlopess@php.net>2008-01-13 14:44:29 +0000
committerNuno Lopes <nlopess@php.net>2008-01-13 14:44:29 +0000
commit18107c0b44a39ebbc2b5f7fab399c0f0e1679196 (patch)
tree8268ef076ede0e93c35629cb906b14f9bd8d67da
parent4c501a0ab62a1978d4583a4a96c557c420aed22f (diff)
downloadphp-git-18107c0b44a39ebbc2b5f7fab399c0f0e1679196.tar.gz
Fixed bug #42945 (preg_split() swallows part of the string)
-rw-r--r--NEWS1
-rw-r--r--ext/pcre/php_pcre.c4
-rw-r--r--ext/pcre/tests/bug42945.phpt88
3 files changed, 92 insertions, 1 deletions
diff --git a/NEWS b/NEWS
index 0039722215..8ba0a2a2a6 100644
--- 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)
diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c
index 9e2187d649..07abff432f 100644
--- a/ext/pcre/php_pcre.c
+++ b/ext/pcre/php_pcre.c
@@ -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
index 0000000000..c6d2b82493
--- /dev/null
+++ b/ext/pcre/tests/bug42945.phpt
@@ -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)
+ }
+}