From 282355efd5d53ba180d30794737c33898031104e Mon Sep 17 00:00:00 2001 From: Dharman Date: Mon, 15 Mar 2021 12:21:44 +0000 Subject: Fix bug #80866 Closes GH-6774. --- NEWS | 4 ++++ ext/pcre/php_pcre.c | 4 ++++ ext/pcre/tests/bug80866.phpt | 12 ++++++++++++ 3 files changed, 20 insertions(+) create mode 100644 ext/pcre/tests/bug80866.phpt diff --git a/NEWS b/NEWS index 64b29572af..264991b16b 100644 --- a/NEWS +++ b/NEWS @@ -23,6 +23,10 @@ PHP NEWS - opcache: . Fixed bug #80805 (create simple class and get error in opcache.so). (Nikita) +- PCRE: + . Fixed bug #80866 (preg_split ignores limit flag when pattern with \K has + 0-width fullstring match). (Kamil Tekiela) + - phpdbg: . Fixed bug #80757 (Exit code is 0 when could not open file). (Felipe) diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index 39896bb07b..19b1069978 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -2644,6 +2644,10 @@ matched: the match again at the same point. If this fails (picked up above) we advance to the next character. */ if (start_offset == offsets[0]) { + /* Get next piece if no limit or limit not yet reached and something matched*/ + if (limit_val != -1 && limit_val <= 1) { + break; + } count = pcre2_match(pce->re, (PCRE2_SPTR)subject, ZSTR_LEN(subject_str), start_offset, PCRE2_NO_UTF_CHECK | PCRE2_NOTEMPTY_ATSTART | PCRE2_ANCHORED, match_data, mctx); if (count >= 0) { diff --git a/ext/pcre/tests/bug80866.phpt b/ext/pcre/tests/bug80866.phpt new file mode 100644 index 0000000000..1de5390cb3 --- /dev/null +++ b/ext/pcre/tests/bug80866.phpt @@ -0,0 +1,12 @@ +--TEST-- +Bug #80866 preg_split ignores limit flag when pattern with \K has 0-width fullstring match +--FILE-- + +--EXPECT-- +array ( + 0 => 'abc', + 1 => 'def', + 2 => 'ghijklm', +) -- cgit v1.2.1