Skip to content

Commit e7e1545

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fix #78853: preg_match() may return integer > 1
2 parents 501a72e + cfb643c commit e7e1545

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

ext/pcre/php_pcre.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1338,7 +1338,11 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, zend_string *subject_str,
13381338
count = pcre2_match(pce->re, (PCRE2_SPTR)subject, subject_len, start_offset2,
13391339
PCRE2_NO_UTF_CHECK | PCRE2_NOTEMPTY_ATSTART | PCRE2_ANCHORED, match_data, mctx);
13401340
if (count >= 0) {
1341-
goto matched;
1341+
if (global) {
1342+
goto matched;
1343+
} else {
1344+
break;
1345+
}
13421346
} else if (count == PCRE2_ERROR_NOMATCH) {
13431347
/* If we previously set PCRE2_NOTEMPTY_ATSTART after a null match,
13441348
this is not necessarily the end. We need to advance

ext/pcre/tests/bug78853.phpt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
--TEST--
2+
Bug #78853 (preg_match() may return integer > 1)
3+
--FILE--
4+
<?php
5+
var_dump(preg_match('/^|\d{1,2}$/', "7"));
6+
?>
7+
--EXPECT--
8+
int(1)

0 commit comments

Comments
 (0)