From f4927c28bc3b1d7d50a81c9cd1655d003b4a8202 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Sat, 6 Nov 2010 18:32:10 +0000 Subject: [PATCH] - Fixed bug #52732 (Docs say preg_match() returns FALSE on error, but it returns int(0)) patch by: slugonamission at gmail dot com --- NEWS | 2 ++ ext/pcre/php_pcre.c | 8 +++++++- ext/pcre/tests/backtrack_limit.phpt | 2 +- ext/pcre/tests/bug52732.phpt | 13 +++++++++++++ ext/pcre/tests/invalid_utf8_offset.phpt | 2 +- ext/pcre/tests/recursion_limit.phpt | 2 +- 6 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 ext/pcre/tests/bug52732.phpt diff --git a/NEWS b/NEWS index 9065131c20..bdc615391e 100644 --- a/NEWS +++ b/NEWS @@ -106,6 +106,8 @@ get_class_name before calling it). (Kalle, Gustavo) - Fixed bug #52744 (cal_days_in_month incorrect for December 1 BCE). (gpap at internet dot gr, Adam) +- Fixed bug #52732 (Docs say preg_match() returns FALSE on error, but it + returns int(0)). (slugonamission at gmail dot com) - Fixed bug #52725 (gcc builtin atomic functions were sometimes used when they were not available). (fat) - Fixed bug #52745 (Binding params doesn't work when selecting a date inside a diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index ccb0a51c0e..ef7e051d86 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -754,7 +754,13 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, int subjec efree(offsets); efree(subpat_names); - RETVAL_LONG(matched); + /* Did we encounter an error? */ + if(PCRE_G(error_code) == PHP_PCRE_NO_ERROR) { + RETVAL_LONG(matched); + } + else { + RETVAL_FALSE; + } } /* }}} */ diff --git a/ext/pcre/tests/backtrack_limit.phpt b/ext/pcre/tests/backtrack_limit.phpt index 517e727016..419e6c2009 100644 --- a/ext/pcre/tests/backtrack_limit.phpt +++ b/ext/pcre/tests/backtrack_limit.phpt @@ -19,7 +19,7 @@ var_dump(preg_last_error() === PREG_NO_ERROR); ?> --EXPECT-- -int(0) +bool(false) bool(true) int(10) bool(true) diff --git a/ext/pcre/tests/bug52732.phpt b/ext/pcre/tests/bug52732.phpt new file mode 100644 index 0000000000..8cfa20420f --- /dev/null +++ b/ext/pcre/tests/bug52732.phpt @@ -0,0 +1,13 @@ +--TEST-- +Bug #52732 (Docs say preg_match() returns FALSE on error, but it returns int(0)) +--INI-- +pcre.backtrack_limit=1 +--FILE-- +)*[!?]/', 'foobar foobar foobar'); + +var_dump($ret); + +?> +--EXPECT-- +bool(false) \ No newline at end of file diff --git a/ext/pcre/tests/invalid_utf8_offset.phpt b/ext/pcre/tests/invalid_utf8_offset.phpt index b6ec1e596f..50716ca9b2 100644 --- a/ext/pcre/tests/invalid_utf8_offset.phpt +++ b/ext/pcre/tests/invalid_utf8_offset.phpt @@ -22,7 +22,7 @@ var_dump(preg_last_error() == PREG_NO_ERROR); echo "Done\n"; ?> --EXPECT-- -int(0) +bool(false) array(0) { } bool(true) diff --git a/ext/pcre/tests/recursion_limit.phpt b/ext/pcre/tests/recursion_limit.phpt index 9933b5c4d7..7dee7ba4e7 100644 --- a/ext/pcre/tests/recursion_limit.phpt +++ b/ext/pcre/tests/recursion_limit.phpt @@ -19,7 +19,7 @@ var_dump(preg_last_error() === PREG_NO_ERROR); ?> --EXPECT-- -int(0) +bool(false) bool(true) int(1) bool(true) -- 2.40.0