From 3a74d987b2c73e9bf007bc7706502a77bc86454e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Tue, 18 Aug 2020 12:33:23 +0200 Subject: [PATCH] Promote warnings to exxceptions in ext/pcre --- ext/pcre/php_pcre.c | 32 ++++--- ext/pcre/tests/002.phpt | 20 ++-- ext/pcre/tests/bug73392.phpt | 27 ++++-- ext/pcre/tests/delimiters.phpt | 69 +++++++++----- ext/pcre/tests/errors03.phpt | 12 ++- ext/pcre/tests/match_flags3.phpt | 9 +- ext/pcre/tests/null_bytes.phpt | 94 ++++++++++++++----- ext/pcre/tests/preg_grep_error1.phpt | 26 ++--- ext/pcre/tests/preg_match_all_error1.phpt | 26 ++--- ext/pcre/tests/preg_match_error1.phpt | 26 ++--- .../tests/preg_replace_callback_array2.phpt | 17 ++-- .../tests/preg_replace_callback_error1.phpt | 24 ++--- ext/pcre/tests/preg_replace_error1.phpt | 28 +++--- ext/pcre/tests/preg_split_error1.phpt | 31 +++--- 14 files changed, 245 insertions(+), 196 deletions(-) diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index acaeb19dc68ca..285d55bc31aa7 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -543,7 +543,7 @@ static zend_string **make_subpats_table(uint32_t num_subpats, pcre_cache_entry * const char *name = name_table + 2; subpat_names[name_idx] = zend_string_init(name, strlen(name), 0); if (is_numeric_string(ZSTR_VAL(subpat_names[name_idx]), ZSTR_LEN(subpat_names[name_idx]), NULL, NULL, 0) > 0) { - php_error_docref(NULL, E_WARNING, "Numeric named subpatterns are not allowed"); + zend_value_error("%s(): Numeric named subpatterns are not allowed", get_active_function_name()); free_subpats_table(subpat_names, num_subpats); return NULL; } @@ -621,8 +621,12 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache_ex(zend_string *regex, in if (key != regex) { zend_string_release_ex(key, 0); } - php_error_docref(NULL, E_WARNING, - p < ZSTR_VAL(regex) + ZSTR_LEN(regex) ? "Null byte in regex" : "Empty regular expression"); + + if (p < ZSTR_VAL(regex) + ZSTR_LEN(regex)) { + zend_type_error("%s(): Regular expression cannot contain any null-bytes", get_active_function_name()); + } else { + zend_value_error("%s(): Regular expression cannot be empty", get_active_function_name()); + } pcre_handle_exec_error(PCRE2_ERROR_INTERNAL); return NULL; } @@ -634,7 +638,7 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache_ex(zend_string *regex, in if (key != regex) { zend_string_release_ex(key, 0); } - php_error_docref(NULL,E_WARNING, "Delimiter must not be alphanumeric or backslash"); + zend_value_error("%s(): Regular expression delimiter cannot be alphanumeric or a backslash", get_active_function_name()); pcre_handle_exec_error(PCRE2_ERROR_INTERNAL); return NULL; } @@ -678,11 +682,11 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache_ex(zend_string *regex, in zend_string_release_ex(key, 0); } if (pp < ZSTR_VAL(regex) + ZSTR_LEN(regex)) { - php_error_docref(NULL,E_WARNING, "Null byte in regex"); + zend_type_error("%s(): Regular expression cannot contain any null-bytes", get_active_function_name()); } else if (start_delimiter == end_delimiter) { - php_error_docref(NULL,E_WARNING, "No ending delimiter '%c' found", delimiter); + zend_value_error("%s(): Regular expression doesn't contain an ending delimiter \"%c\"", get_active_function_name(), delimiter); } else { - php_error_docref(NULL,E_WARNING, "No ending matching delimiter '%c' found", delimiter); + zend_value_error("%s(): No ending matching delimiter \"%c\" found", get_active_function_name(), delimiter); } pcre_handle_exec_error(PCRE2_ERROR_INTERNAL); return NULL; @@ -731,9 +735,9 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache_ex(zend_string *regex, in default: if (pp[-1]) { - php_error_docref(NULL,E_WARNING, "Unknown modifier '%c'", pp[-1]); + zend_value_error("%s(): Regular expression modifier \"%c\" is invalid", get_active_function_name(), pp[-1]); } else { - php_error_docref(NULL,E_WARNING, "Null byte in regex"); + zend_type_error("%s(): Regular expression cannot contain any null-bytes", get_active_function_name()); } pcre_handle_exec_error(PCRE2_ERROR_INTERNAL); efree(pattern); @@ -745,7 +749,7 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache_ex(zend_string *regex, in } if (poptions & PREG_REPLACE_EVAL) { - php_error_docref(NULL, E_WARNING, "The /e modifier is no longer supported, use preg_replace_callback instead"); + zend_value_error("%s(): Regular expression modifier \"e\" is no longer supported, use preg_replace_callback instead", get_active_function_name()); pcre_handle_exec_error(PCRE2_ERROR_INTERNAL); efree(pattern); if (key != regex) { @@ -1193,7 +1197,7 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, zend_string *subject_str, } if ((global && (subpats_order < PREG_PATTERN_ORDER || subpats_order > PREG_SET_ORDER)) || (!global && subpats_order != 0)) { - php_error_docref(NULL, E_WARNING, "Invalid flags specified"); + zend_argument_value_error(4, "must be a PREG_* constant"); return; } } else { @@ -2404,15 +2408,13 @@ PHP_FUNCTION(preg_replace_callback_array) ZEND_HASH_FOREACH_STR_KEY_VAL(pattern, str_idx_regex, replace) { if (!str_idx_regex) { - php_error_docref(NULL, E_WARNING, "Delimiter must not be alphanumeric or backslash"); + zend_value_error("%s(): Regular expression delimiter cannot be alphanumeric or a backslash", get_active_function_name()); zval_ptr_dtor(return_value); RETURN_NULL(); } if (!zend_is_callable_ex(replace, NULL, 0, NULL, &fcc, NULL)) { - zend_string *callback_name = zend_get_callable_name(replace); - zend_type_error("'%s' is not a valid callback", ZSTR_VAL(callback_name)); - zend_string_release_ex(callback_name, 0); + zend_argument_type_error(1, "must contain only valid callbacks"); RETURN_THROWS(); } diff --git a/ext/pcre/tests/002.phpt b/ext/pcre/tests/002.phpt index 073a7a8d566ef..ac8ae95213ade 100644 --- a/ext/pcre/tests/002.phpt +++ b/ext/pcre/tests/002.phpt @@ -3,23 +3,29 @@ preg_* with bogus vals --FILE-- getMessage() . "\n"; +} var_dump(preg_quote('')); var_dump(preg_replace('/(.)/', '${1}${1', 'abc')); var_dump(preg_replace('/.++\d*+[/', 'for ($', 'abc')); -var_dump(preg_replace('/(.)/e', 'for ($', 'abc')); + +try { + preg_replace('/(.)/e', 'for ($', 'abc'); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} ?> --EXPECTF-- -Warning: preg_match_all(): Invalid flags specified in %s002.php on line %d -NULL +preg_match_all(): Argument #4 ($flags) must be a PREG_* constant string(0) "" string(12) "a${1b${1c${1" Warning: preg_replace(): Compilation failed: missing terminating ] for character class at offset 8 in %s002.php on line %d NULL - -Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in %s on line %d -NULL +preg_replace(): Regular expression modifier "e" is no longer supported, use preg_replace_callback instead diff --git a/ext/pcre/tests/bug73392.phpt b/ext/pcre/tests/bug73392.phpt index 704cc3d3515bc..bff8bf62ab087 100644 --- a/ext/pcre/tests/bug73392.phpt +++ b/ext/pcre/tests/bug73392.phpt @@ -15,13 +15,22 @@ class Foo { function b() { return "b"; } -var_dump(preg_replace_callback_array( - array( - "/a/" => 'b', "/b/" => function () { return "c"; }, "/c/" => new Rep, "reporting" => array("Foo", "rep"), "a1" => array("Foo", "rep"), - ), 'a')); -?> ---EXPECTF-- -Warning: preg_replace_callback_array(): Delimiter must not be alphanumeric or backslash in %sbug73392.php on line %d -Warning: preg_replace_callback_array(): Delimiter must not be alphanumeric or backslash in %sbug73392.php on line %d -NULL +try { + preg_replace_callback_array( + array( + "/a/" => 'b', + "/b/" => function () { return "c"; }, + "/c/" => new Rep, + "reporting" => array("Foo", "rep"), + "a1" => array("Foo", "rep"), + ), + 'a' + ); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} + +?> +--EXPECT-- +preg_replace_callback_array(): Regular expression delimiter cannot be alphanumeric or a backslash diff --git a/ext/pcre/tests/delimiters.phpt b/ext/pcre/tests/delimiters.phpt index 1826f8730a337..74cf133762373 100644 --- a/ext/pcre/tests/delimiters.phpt +++ b/ext/pcre/tests/delimiters.phpt @@ -3,35 +3,56 @@ Delimiters crash test --FILE-- getMessage() . "\n"; +} + +try { + preg_match(' ', ''); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} + var_dump(preg_match('@@', '')); -var_dump(preg_match('12', '')); + +try { + preg_match('12', ''); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} + var_dump(preg_match('<>', '')); -var_dump(preg_match('~a', '')); + +try { + preg_match('~a', ''); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} + var_dump(preg_match('@\@\@@', '@@')); -var_dump(preg_match('//z', '@@')); -var_dump(preg_match('{', '')); -?> ---EXPECTF-- -Warning: preg_match(): Empty regular expression in %sdelimiters.php on line 3 -bool(false) +try { + preg_match('//z', '@@'); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} -Warning: preg_match(): Empty regular expression in %sdelimiters.php on line 4 -bool(false) -int(1) +try { + preg_match('{', ''); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} -Warning: preg_match(): Delimiter must not be alphanumeric or backslash in %sdelimiters.php on line 6 -bool(false) +?> +--EXPECT-- +preg_match(): Regular expression cannot be empty +preg_match(): Regular expression cannot be empty int(1) - -Warning: preg_match(): No ending delimiter '~' found in %sdelimiters.php on line 8 -bool(false) +preg_match(): Regular expression delimiter cannot be alphanumeric or a backslash int(1) - -Warning: preg_match(): Unknown modifier 'z' in %sdelimiters.php on line 10 -bool(false) - -Warning: preg_match(): No ending matching delimiter '}' found in %sdelimiters.php on line 11 -bool(false) +preg_match(): Regular expression doesn't contain an ending delimiter "~" +int(1) +preg_match(): Regular expression modifier "z" is invalid +preg_match(): No ending matching delimiter "}" found diff --git a/ext/pcre/tests/errors03.phpt b/ext/pcre/tests/errors03.phpt index 1f519cb599958..8888dfb6b9d22 100644 --- a/ext/pcre/tests/errors03.phpt +++ b/ext/pcre/tests/errors03.phpt @@ -3,11 +3,15 @@ Test preg_match() function : error conditions - Internal error --FILE-- getMessage() . "\n"; +} + var_dump(preg_last_error_msg() === 'Internal error'); ?> ---EXPECTF-- -Warning: preg_match(): No ending delimiter '/' found in %s on line %d -bool(false) +--EXPECT-- +preg_match(): Regular expression doesn't contain an ending delimiter "/" bool(true) diff --git a/ext/pcre/tests/match_flags3.phpt b/ext/pcre/tests/match_flags3.phpt index 6511c715e11eb..ffc5dae96cbfc 100644 --- a/ext/pcre/tests/match_flags3.phpt +++ b/ext/pcre/tests/match_flags3.phpt @@ -3,7 +3,11 @@ preg_match() flags 3 --FILE-- getMessage() . "\n"; +} var_dump(preg_match('/\d+/', '123 456 789 012', $match, 0, -8)); var_dump($match); @@ -18,8 +22,7 @@ var_dump(preg_match('/(?P<3>)/', '')); ?> --EXPECTF-- -Warning: preg_match(): Empty regular expression in %smatch_flags3.php on line 3 -bool(false) +preg_match(): Regular expression cannot be empty int(1) array(1) { [0]=> diff --git a/ext/pcre/tests/null_bytes.phpt b/ext/pcre/tests/null_bytes.phpt index 9a3f433ffb1bc..dba642e052379 100644 --- a/ext/pcre/tests/null_bytes.phpt +++ b/ext/pcre/tests/null_bytes.phpt @@ -3,40 +3,82 @@ Zero byte test --FILE-- getMessage() . "\n"; +} -preg_match("\0[]i", ""); -preg_match("[\0]i", ""); -preg_match("[]\0i", ""); -preg_match("[]i\0", ""); -preg_match("[\\\0]i", ""); +try { + preg_match("/\0/i", ""); +} catch (TypeError $exception) { + echo $exception->getMessage() . "\n"; +} -preg_replace("/foo/e\0/i", "echo('Eek');", ""); +try { + preg_match("//\0i", ""); +} catch (TypeError $exception) { + echo $exception->getMessage() . "\n"; +} -?> ---EXPECTF-- -Warning: preg_match(): Null byte in regex in %snull_bytes.php on line 3 - -Warning: preg_match(): Null byte in regex in %snull_bytes.php on line 4 +try { + preg_match("//i\0", ""); +} catch (TypeError $exception) { + echo $exception->getMessage() . "\n"; +} -Warning: preg_match(): Null byte in regex in %snull_bytes.php on line 5 +try { + preg_match("/\\\0/i", ""); +} catch (TypeError $exception) { + echo $exception->getMessage() . "\n"; +} -Warning: preg_match(): Null byte in regex in %snull_bytes.php on line 6 +try { + preg_match("\0[]i", ""); +} catch (TypeError $exception) { + echo $exception->getMessage() . "\n"; +} -Warning: preg_match(): Null byte in regex in %snull_bytes.php on line 7 +try { + preg_match("[\0]i", ""); +} catch (TypeError $exception) { + echo $exception->getMessage() . "\n"; +} -Warning: preg_match(): Null byte in regex in %snull_bytes.php on line 9 +try { + preg_match("[]\0i", ""); +} catch (TypeError $exception) { + echo $exception->getMessage() . "\n"; +} -Warning: preg_match(): Null byte in regex in %snull_bytes.php on line 10 +try { + preg_match("[]i\0", ""); +} catch (TypeError $exception) { + echo $exception->getMessage() . "\n"; +} -Warning: preg_match(): Null byte in regex in %snull_bytes.php on line 11 +try { + preg_match("[\\\0]i", ""); +} catch (TypeError $exception) { + echo $exception->getMessage() . "\n"; +} -Warning: preg_match(): Null byte in regex in %snull_bytes.php on line 12 +try { + preg_replace("/foo/e\0/i", "echo('Eek');", ""); +} catch (TypeError $exception) { + echo $exception->getMessage() . "\n"; +} -Warning: preg_match(): Null byte in regex in %snull_bytes.php on line 13 - -Warning: preg_replace(): Null byte in regex in %snull_bytes.php on line 15 +?> +--EXPECT-- +preg_match(): Regular expression cannot contain any null-bytes +preg_match(): Regular expression cannot contain any null-bytes +preg_match(): Regular expression cannot contain any null-bytes +preg_match(): Regular expression cannot contain any null-bytes +preg_match(): Regular expression cannot contain any null-bytes +preg_match(): Regular expression cannot contain any null-bytes +preg_match(): Regular expression cannot contain any null-bytes +preg_match(): Regular expression cannot contain any null-bytes +preg_match(): Regular expression cannot contain any null-bytes +preg_match(): Regular expression cannot contain any null-bytes +preg_replace(): Regular expression cannot contain any null-bytes diff --git a/ext/pcre/tests/preg_grep_error1.phpt b/ext/pcre/tests/preg_grep_error1.phpt index 1215c24f009c3..7f92c264d1b36 100644 --- a/ext/pcre/tests/preg_grep_error1.phpt +++ b/ext/pcre/tests/preg_grep_error1.phpt @@ -20,43 +20,35 @@ foreach($values as $value) { @print "\nArg value is $value\n"; try { var_dump(preg_grep($value, $array)); - } catch (TypeError $e) { - echo $e->getMessage(), "\n"; + } catch (Error $e) { + echo get_class($e) . ": " . $e->getMessage(), "\n"; } } $value = new stdclass(); //Object try { - var_dump(preg_grep($value, $array)); + preg_grep($value, $array); } catch (TypeError $e) { echo $e->getMessage(), "\n"; } echo "Done" ?> ---EXPECTF-- +--EXPECT-- *** Testing preg_grep() : error conditions *** Arg value is abcdef - -Warning: preg_grep(): Delimiter must not be alphanumeric or backslash in %spreg_grep_error1.php on line %d -bool(false) +ValueError: preg_grep(): Regular expression delimiter cannot be alphanumeric or a backslash Arg value is /[a-zA-Z] - -Warning: preg_grep(): No ending delimiter '/' found in %spreg_grep_error1.php on line %d -bool(false) +ValueError: preg_grep(): Regular expression doesn't contain an ending delimiter "/" Arg value is [a-zA-Z]/ - -Warning: preg_grep(): Unknown modifier '/' in %spreg_grep_error1.php on line %d -bool(false) +ValueError: preg_grep(): Regular expression modifier "/" is invalid Arg value is /[a-zA-Z]/F - -Warning: preg_grep(): Unknown modifier 'F' in %spreg_grep_error1.php on line %d -bool(false) +ValueError: preg_grep(): Regular expression modifier "F" is invalid Arg value is Array -preg_grep(): Argument #1 ($regex) must be of type string, array given +TypeError: preg_grep(): Argument #1 ($regex) must be of type string, array given Arg value is /[a-zA-Z]/ array(2) { diff --git a/ext/pcre/tests/preg_match_all_error1.phpt b/ext/pcre/tests/preg_match_all_error1.phpt index d25bfe99c6e6d..f70dcf68c00bc 100644 --- a/ext/pcre/tests/preg_match_all_error1.phpt +++ b/ext/pcre/tests/preg_match_all_error1.phpt @@ -20,48 +20,40 @@ foreach($regex_array as $regex_value) { @print "\nArg value is $regex_value\n"; try { var_dump(preg_match_all($regex_value, $subject, $matches1)); - } catch (TypeError $e) { - echo $e->getMessage(), "\n"; + } catch (Error $e) { + echo get_class($e) . ": " . $e->getMessage(), "\n"; } var_dump($matches1); } $regex_value = new stdclass(); //Object try { - var_dump(preg_match_all($regex_value, $subject, $matches)); + preg_match_all($regex_value, $subject, $matches); } catch (TypeError $e) { echo $e->getMessage(), "\n"; } var_dump($matches); ?> ---EXPECTF-- +--EXPECT-- *** Testing preg_match_all() : error conditions *** Arg value is abcdef - -Warning: preg_match_all(): Delimiter must not be alphanumeric or backslash in %spreg_match_all_error1.php on line %d -bool(false) +ValueError: preg_match_all(): Regular expression delimiter cannot be alphanumeric or a backslash NULL Arg value is /[a-zA-Z] - -Warning: preg_match_all(): No ending delimiter '/' found in %spreg_match_all_error1.php on line %d -bool(false) +ValueError: preg_match_all(): Regular expression doesn't contain an ending delimiter "/" NULL Arg value is [a-zA-Z]/ - -Warning: preg_match_all(): Unknown modifier '/' in %spreg_match_all_error1.php on line %d -bool(false) +ValueError: preg_match_all(): Regular expression modifier "/" is invalid NULL Arg value is /[a-zA-Z]/F - -Warning: preg_match_all(): Unknown modifier 'F' in %spreg_match_all_error1.php on line %d -bool(false) +ValueError: preg_match_all(): Regular expression modifier "F" is invalid NULL Arg value is Array -preg_match_all(): Argument #1 ($pattern) must be of type string, array given +TypeError: preg_match_all(): Argument #1 ($pattern) must be of type string, array given NULL Arg value is /[a-zA-Z]/ diff --git a/ext/pcre/tests/preg_match_error1.phpt b/ext/pcre/tests/preg_match_error1.phpt index 7a7106270f0e8..94873dd63413f 100644 --- a/ext/pcre/tests/preg_match_error1.phpt +++ b/ext/pcre/tests/preg_match_error1.phpt @@ -18,42 +18,34 @@ foreach($regex_array as $regex_value) { @print "\nArg value is $regex_value\n"; try { var_dump(preg_match($regex_value, $subject)); - } catch (TypeError $e) { - echo $e->getMessage(), "\n"; + } catch (Error $e) { + echo get_class($e) . ": " . $e->getMessage(), "\n"; } } $regex_value = new stdclass(); //Object try { - var_dump(preg_match($regex_value, $subject)); + preg_match($regex_value, $subject); } catch (TypeError $e) { echo $e->getMessage(), "\n"; } ?> ---EXPECTF-- +--EXPECT-- *** Testing preg_match() : error conditions *** Arg value is abcdef - -Warning: preg_match(): Delimiter must not be alphanumeric or backslash in %spreg_match_error1.php on line %d -bool(false) +ValueError: preg_match(): Regular expression delimiter cannot be alphanumeric or a backslash Arg value is /[a-zA-Z] - -Warning: preg_match(): No ending delimiter '/' found in %spreg_match_error1.php on line %d -bool(false) +ValueError: preg_match(): Regular expression doesn't contain an ending delimiter "/" Arg value is [a-zA-Z]/ - -Warning: preg_match(): Unknown modifier '/' in %spreg_match_error1.php on line %d -bool(false) +ValueError: preg_match(): Regular expression modifier "/" is invalid Arg value is /[a-zA-Z]/F - -Warning: preg_match(): Unknown modifier 'F' in %spreg_match_error1.php on line %d -bool(false) +ValueError: preg_match(): Regular expression modifier "F" is invalid Arg value is Array -preg_match(): Argument #1 ($pattern) must be of type string, array given +TypeError: preg_match(): Argument #1 ($pattern) must be of type string, array given Arg value is /[a-zA-Z]/ int(1) diff --git a/ext/pcre/tests/preg_replace_callback_array2.phpt b/ext/pcre/tests/preg_replace_callback_array2.phpt index 679a4b0c54ec2..9b084a9871197 100644 --- a/ext/pcre/tests/preg_replace_callback_array2.phpt +++ b/ext/pcre/tests/preg_replace_callback_array2.phpt @@ -19,21 +19,22 @@ function f() { throw new Exception($count); } -var_dump(preg_replace_callback_array(array('/\w' => 'f'), 'z')); - try { - var_dump(preg_replace_callback_array(array('/\w/' => 'f', '/.*/' => 'f'), 'z')); + preg_replace_callback_array(array('/\w' => 'f'), 'z'); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} +try { + preg_replace_callback_array(array('/\w/' => 'f', '/.*/' => 'f'), 'z'); } catch (Exception $e) { var_dump($e->getMessage()); } echo "Done\n"; ?> ---EXPECTF-- -'s' is not a valid callback +--EXPECT-- +preg_replace_callback_array(): Argument #1 ($pattern) must contain only valid callbacks string(0) "" - -Warning: preg_replace_callback_array(): No ending delimiter '/' found in %spreg_replace_callback_array2.php on line %d -NULL +preg_replace_callback_array(): Regular expression doesn't contain an ending delimiter "/" string(1) "1" Done diff --git a/ext/pcre/tests/preg_replace_callback_error1.phpt b/ext/pcre/tests/preg_replace_callback_error1.phpt index eb6478e506952..c4844879372ee 100644 --- a/ext/pcre/tests/preg_replace_callback_error1.phpt +++ b/ext/pcre/tests/preg_replace_callback_error1.phpt @@ -22,31 +22,27 @@ function integer_word($matches) { $subject = 'number 1.'; foreach($regex_array as $regex_value) { @print "\nArg value is $regex_value\n"; - var_dump(preg_replace_callback($regex_value, 'integer_word', $subject)); + try { + var_dump(preg_replace_callback($regex_value, 'integer_word', $subject)); + } catch (Error $exception) { + echo get_class($exception) . ": " . $exception->getMessage() . "\n"; + } } ?> ---EXPECTF-- +--EXPECT-- *** Testing preg_replace_callback() : error conditions *** Arg value is abcdef - -Warning: preg_replace_callback(): Delimiter must not be alphanumeric or backslash in %s on line %d -NULL +ValueError: preg_replace_callback(): Regular expression delimiter cannot be alphanumeric or a backslash Arg value is /[a-zA-Z] - -Warning: preg_replace_callback(): No ending delimiter '/' found in %s on line %d -NULL +ValueError: preg_replace_callback(): Regular expression doesn't contain an ending delimiter "/" Arg value is [a-zA-Z]/ - -Warning: preg_replace_callback(): Unknown modifier '/' in %s on line %d -NULL +ValueError: preg_replace_callback(): Regular expression modifier "/" is invalid Arg value is /[a-zA-Z]/F - -Warning: preg_replace_callback(): Unknown modifier 'F' in %s on line %d -NULL +ValueError: preg_replace_callback(): Regular expression modifier "F" is invalid Arg value is Array string(9) "number 1." diff --git a/ext/pcre/tests/preg_replace_error1.phpt b/ext/pcre/tests/preg_replace_error1.phpt index 58cd049691a97..3d763fe104e18 100644 --- a/ext/pcre/tests/preg_replace_error1.phpt +++ b/ext/pcre/tests/preg_replace_error1.phpt @@ -19,37 +19,33 @@ $replace = 1; $subject = 'a'; foreach($regex_array as $regex_value) { @print "\nArg value is $regex_value\n"; - var_dump(preg_replace($regex_value, $replace, $subject)); + try { + var_dump(preg_replace($regex_value, $replace, $subject)); + } catch (Error $e) { + echo $e->getMessage(), "\n"; + } } $regex_value = new stdclass(); //Object try { - var_dump(preg_replace($regex_value, $replace, $subject)); -} catch (Error $e) { + preg_replace($regex_value, $replace, $subject); +} catch (TypeError $e) { echo $e->getMessage(), "\n"; } ?> ---EXPECTF-- +--EXPECT-- *** Testing preg_replace() : error conditions*** Arg value is abcdef - -Warning: preg_replace(): Delimiter must not be alphanumeric or backslash in %spreg_replace_error1.php on line %d -NULL +preg_replace(): Regular expression delimiter cannot be alphanumeric or a backslash Arg value is /[a-zA-Z] - -Warning: preg_replace(): No ending delimiter '/' found in %spreg_replace_error1.php on line %d -NULL +preg_replace(): Regular expression doesn't contain an ending delimiter "/" Arg value is [a-zA-Z]/ - -Warning: preg_replace(): Unknown modifier '/' in %spreg_replace_error1.php on line %d -NULL +preg_replace(): Regular expression modifier "/" is invalid Arg value is /[a-zA-Z]/F - -Warning: preg_replace(): Unknown modifier 'F' in %spreg_replace_error1.php on line %d -NULL +preg_replace(): Regular expression modifier "F" is invalid Arg value is Array string(1) "a" diff --git a/ext/pcre/tests/preg_split_error1.phpt b/ext/pcre/tests/preg_split_error1.phpt index 4d0fb9e22a45e..5bb78834df9e8 100644 --- a/ext/pcre/tests/preg_split_error1.phpt +++ b/ext/pcre/tests/preg_split_error1.phpt @@ -20,42 +20,35 @@ foreach($regex_array as $regex_value) { @print "\nArg value is $regex_value\n"; try { var_dump(preg_split($regex_value, $subject)); - } catch (TypeError $e) { - echo $e->getMessage(), "\n"; + } catch (Error $exception) { + echo get_class($exception) . ": " . $exception->getMessage() . "\n"; } } $regex_value = new stdclass(); //Object try { - var_dump(preg_split($regex_value, $subject)); -} catch (TypeError $e) { - echo $e->getMessage(), "\n"; + preg_split($regex_value, $subject); +} catch (TypeError $exception) { + echo $exception->getMessage() . "\n"; } + ?> ---EXPECTF-- +--EXPECT-- *** Testing preg_split() : error conditions *** Arg value is abcdef - -Warning: preg_split(): Delimiter must not be alphanumeric or backslash in %spreg_split_error1.php on line %d -bool(false) +ValueError: preg_split(): Regular expression delimiter cannot be alphanumeric or a backslash Arg value is /[a-zA-Z] - -Warning: preg_split(): No ending delimiter '/' found in %spreg_split_error1.php on line %d -bool(false) +ValueError: preg_split(): Regular expression doesn't contain an ending delimiter "/" Arg value is [a-zA-Z]/ - -Warning: preg_split(): Unknown modifier '/' in %spreg_split_error1.php on line %d -bool(false) +ValueError: preg_split(): Regular expression modifier "/" is invalid Arg value is /[a-zA-Z]/F - -Warning: preg_split(): Unknown modifier 'F' in %spreg_split_error1.php on line %d -bool(false) +ValueError: preg_split(): Regular expression modifier "F" is invalid Arg value is Array -preg_split(): Argument #1 ($pattern) must be of type string, array given +TypeError: preg_split(): Argument #1 ($pattern) must be of type string, array given Arg value is /[a-zA-Z]/ array(3) {