summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2021-03-15 14:47:50 +0100
committerNikita Popov <nikita.ppv@gmail.com>2021-03-15 14:48:02 +0100
commit50254de0a2cc63570a5caf7666151a77e7bd0b7a (patch)
tree23259a1b2c848b7c4973f567dcb4281c0c237772
parent6493b516f9573f8a9368376b900eb9df758b1d40 (diff)
parent282355efd5d53ba180d30794737c33898031104e (diff)
downloadphp-git-50254de0a2cc63570a5caf7666151a77e7bd0b7a.tar.gz
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4: Fix bug #80866
-rw-r--r--NEWS4
-rw-r--r--ext/pcre/php_pcre.c4
-rw-r--r--ext/pcre/tests/bug80866.phpt12
3 files changed, 20 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index ef515b3c13..5992e61392 100644
--- a/NEWS
+++ b/NEWS
@@ -28,6 +28,10 @@ PHP NEWS
. Fixed bug #80786 (PHP crash using JIT). (Nikita)
. Fixed bug #80782 (DASM_S_RANGE_VREG on PHP_INT_MIN-1). (Dmitry)
+- PCRE:
+ . Fixed bug #80866 (preg_split ignores limit flag when pattern with \K has
+ 0-width fullstring match). (Kamil Tekiela)
+
- Session:
. Fixed bug #80774 (session_name() problem with backslash). (cmb)
diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c
index 4a796062ec..60d0670213 100644
--- a/ext/pcre/php_pcre.c
+++ b/ext/pcre/php_pcre.c
@@ -2640,6 +2640,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--
+<?php
+var_export(preg_split('~.{3}\K~', 'abcdefghijklm', 3));
+?>
+--EXPECT--
+array (
+ 0 => 'abc',
+ 1 => 'def',
+ 2 => 'ghijklm',
+)