From 03cbbf4348b7bd95d0322d3371ce1f85efc1e1aa 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 --- 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 +- 5 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 ext/pcre/tests/bug52732.phpt diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index 1bb9e1a80c..0978e8303a 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