Skip to content

Commit b82b857

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Fix bug #80866
2 parents 5604c2d + 50254de commit b82b857

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

ext/pcre/php_pcre.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2640,6 +2640,10 @@ PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, zend_string *subject_str,
26402640
the match again at the same point. If this fails (picked up above) we
26412641
advance to the next character. */
26422642
if (start_offset == offsets[0]) {
2643+
/* Get next piece if no limit or limit not yet reached and something matched*/
2644+
if (limit_val != -1 && limit_val <= 1) {
2645+
break;
2646+
}
26432647
count = pcre2_match(pce->re, (PCRE2_SPTR)subject, ZSTR_LEN(subject_str), start_offset,
26442648
PCRE2_NO_UTF_CHECK | PCRE2_NOTEMPTY_ATSTART | PCRE2_ANCHORED, match_data, mctx);
26452649
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)