Skip to content

Commit 03cbbf4

Browse files
committed
- Fixed bug #52732 (Docs say preg_match() returns FALSE on error, but it returns int(0))
patch by: slugonamission at gmail dot com
1 parent ccfe9c3 commit 03cbbf4

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed

ext/pcre/php_pcre.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,13 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, int subjec
754754
efree(offsets);
755755
efree(subpat_names);
756756

757-
RETVAL_LONG(matched);
757+
/* Did we encounter an error? */
758+
if(PCRE_G(error_code) == PHP_PCRE_NO_ERROR) {
759+
RETVAL_LONG(matched);
760+
}
761+
else {
762+
RETVAL_FALSE;
763+
}
758764
}
759765
/* }}} */
760766

ext/pcre/tests/backtrack_limit.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var_dump(preg_last_error() === PREG_NO_ERROR);
1919

2020
?>
2121
--EXPECT--
22-
int(0)
22+
bool(false)
2323
bool(true)
2424
int(10)
2525
bool(true)

ext/pcre/tests/bug52732.phpt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
Bug #52732 (Docs say preg_match() returns FALSE on error, but it returns int(0))
3+
--INI--
4+
pcre.backtrack_limit=1
5+
--FILE--
6+
<?php
7+
$ret = preg_match('/(?:\D+|<\d+>)*[!?]/', 'foobar foobar foobar');
8+
9+
var_dump($ret);
10+
11+
?>
12+
--EXPECT--
13+
bool(false)

ext/pcre/tests/invalid_utf8_offset.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var_dump(preg_last_error() == PREG_NO_ERROR);
2222
echo "Done\n";
2323
?>
2424
--EXPECT--
25-
int(0)
25+
bool(false)
2626
array(0) {
2727
}
2828
bool(true)

ext/pcre/tests/recursion_limit.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var_dump(preg_last_error() === PREG_NO_ERROR);
1919

2020
?>
2121
--EXPECT--
22-
int(0)
22+
bool(false)
2323
bool(true)
2424
int(1)
2525
bool(true)

0 commit comments

Comments
 (0)