Skip to content

Commit 282355e

Browse files
kamil-tekielanikic
authored andcommitted
Fix bug #80866
Closes GH-6774.
1 parent c93b461 commit 282355e

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ PHP NEWS
2323
- opcache:
2424
. Fixed bug #80805 (create simple class and get error in opcache.so). (Nikita)
2525

26+
- PCRE:
27+
. Fixed bug #80866 (preg_split ignores limit flag when pattern with \K has
28+
0-width fullstring match). (Kamil Tekiela)
29+
2630
- phpdbg:
2731
. Fixed bug #80757 (Exit code is 0 when could not open file). (Felipe)
2832

ext/pcre/php_pcre.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2644,6 +2644,10 @@ PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, zend_string *subject_str,
26442644
the match again at the same point. If this fails (picked up above) we
26452645
advance to the next character. */
26462646
if (start_offset == offsets[0]) {
2647+
/* Get next piece if no limit or limit not yet reached and something matched*/
2648+
if (limit_val != -1 && limit_val <= 1) {
2649+
break;
2650+
}
26472651
count = pcre2_match(pce->re, (PCRE2_SPTR)subject, ZSTR_LEN(subject_str), start_offset,
26482652
PCRE2_NO_UTF_CHECK | PCRE2_NOTEMPTY_ATSTART | PCRE2_ANCHORED, match_data, mctx);
26492653
if (count >= 0) {

ext/pcre/tests/bug80866.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Bug #80866 preg_split ignores limit flag when pattern with \K has 0-width fullstring match
3+
--FILE--
4+
<?php
5+
var_export(preg_split('~.{3}\K~', 'abcdefghijklm', 3));
6+
?>
7+
--EXPECT--
8+
array (
9+
0 => 'abc',
10+
1 => 'def',
11+
2 => 'ghijklm',
12+
)

0 commit comments

Comments
 (0)