From: Nuno Lopes Date: Sun, 13 Jan 2008 14:57:54 +0000 (+0000) Subject: MFB: fix bug #42945 X-Git-Tag: RELEASE_2_0_0a1~923 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fe197abf66d805362c5638d79303a9c4bb66afff;p=php MFB: fix bug #42945 --- diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index 0dcd5bbab0..03ae8cc9ef 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -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 index 0000000000..15a3ed6e9c --- /dev/null +++ b/ext/pcre/tests/bug42945.phpt @@ -0,0 +1,162 @@ +--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) + } +} +--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) + } +}