From: Nuno Lopes Date: Mon, 14 Jan 2008 09:46:55 +0000 (+0000) Subject: MFH: fix bug #42945, as asked by Ilia X-Git-Tag: php-5.2.6RC1~169 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0f9729404fc4b57ca8fee2f6b1dbe9d6746e648a;p=php MFH: fix bug #42945, as asked by Ilia --- diff --git a/NEWS b/NEWS index 4e0c1c78ec..acee9bce40 100644 --- a/NEWS +++ b/NEWS @@ -67,6 +67,7 @@ PHP NEWS - Fixed bug #43105 (PHP seems to fail to close open files). (Hannes) - Fixed bug #42978 (mismatch between number of bound params and values causes a crash in pdo_pgsql). (Ilia) +- Fixed bug #42945 (preg_split() swallows part of the string). (Nuno) - Fixed bug #42937 (__call() method not invoked when methods are called on parent from child class). (Dmitry) - Fixed bug #42736 (xmlrpc_server_call_method() crashes). (Tony) diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index c2445c9fec..9e1d9082b5 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -1535,7 +1535,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-- + +--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) + } +}