Skip to content

Commit 50254de

Browse files
committed
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4: Fix bug #80866
2 parents 6493b51 + 282355e commit 50254de

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
@@ -28,6 +28,10 @@ PHP NEWS
2828
. Fixed bug #80786 (PHP crash using JIT). (Nikita)
2929
. Fixed bug #80782 (DASM_S_RANGE_VREG on PHP_INT_MIN-1). (Dmitry)
3030

31+
- PCRE:
32+
. Fixed bug #80866 (preg_split ignores limit flag when pattern with \K has
33+
0-width fullstring match). (Kamil Tekiela)
34+
3135
- Session:
3236
. Fixed bug #80774 (session_name() problem with backslash). (cmb)
3337

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)