From fe2ebde7f626e4f199c78e58d830bef0659a4668 Mon Sep 17 00:00:00 2001 From: Joey Smith Date: Wed, 18 Oct 2017 00:03:42 -0600 Subject: [PATCH 1/2] Make parenthesized expressions advance the limit count on preg_split --- ext/pcre/php_pcre.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index 44b5ff55b03eb..38d9a7b965e11 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -2287,10 +2287,6 @@ PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, zend_string *subject_str, ZVAL_STRINGL(&tmp, last_match, &ZSTR_VAL(subject_str)[offsets[0]]-last_match); zend_hash_next_index_insert_new(Z_ARRVAL_P(return_value), &tmp); } - - /* One less left to do */ - if (limit_val != -1) - limit_val--; } last_match = &ZSTR_VAL(subject_str)[offsets[1]]; @@ -2312,6 +2308,10 @@ PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, zend_string *subject_str, } } + /* One less left to do */ + if (limit_val != -1) + limit_val--; + /* Advance to the position right after the last full match */ start_offset = offsets[1]; From 39f3547ad5150be45bef4a58cec927a2d7d46264 Mon Sep 17 00:00:00 2001 From: Joey Smith Date: Sun, 22 Oct 2017 00:47:13 -0600 Subject: [PATCH 2/2] Add test for PR #2860 (parenthesized expressions advance the limit count on preg_split) --- ext/pcre/tests/split3.phpt | 64 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 ext/pcre/tests/split3.phpt diff --git a/ext/pcre/tests/split3.phpt b/ext/pcre/tests/split3.phpt new file mode 100644 index 0000000000000..4a705fcb470f8 --- /dev/null +++ b/ext/pcre/tests/split3.phpt @@ -0,0 +1,64 @@ +--TEST-- +preg_split() - parenthesized expressions advance the limit count +--FILE-- + + string(1) "H" + [1]=> + string(17) "AHAHA, VERY FUNNY" +} +array(3) { + [0]=> + string(1) "H" + [1]=> + string(1) "A" + [2]=> + string(16) "HAHA, VERY FUNNY" +} +array(18) { + [0]=> + string(1) "H" + [1]=> + string(1) "A" + [2]=> + string(1) "H" + [3]=> + string(1) "A" + [4]=> + string(1) "H" + [5]=> + string(1) "A" + [6]=> + string(1) "," + [7]=> + string(1) " " + [8]=> + string(1) "V" + [9]=> + string(1) "E" + [10]=> + string(1) "R" + [11]=> + string(1) "Y" + [12]=> + string(1) " " + [13]=> + string(1) "F" + [14]=> + string(1) "U" + [15]=> + string(1) "N" + [16]=> + string(1) "N" + [17]=> + string(1) "Y" +}