Skip to content

Commit

Permalink
Promote warnings to exceptions in ext/pcre
Browse files Browse the repository at this point in the history
Closes GH-6006
  • Loading branch information
kocsismate committed Aug 25, 2020
1 parent 2369f48 commit ea87d04
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
8 changes: 3 additions & 5 deletions ext/pcre/php_pcre.c
Original file line number Diff line number Diff line change
Expand Up @@ -1193,8 +1193,8 @@ 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");
return;
zend_argument_value_error(4, "must be a PREG_* constant");
RETURN_THROWS();
}
} else {
offset_capture = 0;
Expand Down Expand Up @@ -2410,9 +2410,7 @@ PHP_FUNCTION(preg_replace_callback_array)
}

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();
}

Expand Down
9 changes: 6 additions & 3 deletions ext/pcre/tests/002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ preg_* with bogus vals
--FILE--
<?php

var_dump(preg_match_all('//', '', $dummy, 0xdead));
try {
preg_match_all('//', '', $dummy, 0xdead);
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}

var_dump(preg_quote(''));

Expand All @@ -13,8 +17,7 @@ var_dump(preg_replace('/(.)/e', 'for ($', 'abc'));

?>
--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"

Expand Down
2 changes: 1 addition & 1 deletion ext/pcre/tests/preg_replace_callback_array2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ try {
echo "Done\n";
?>
--EXPECTF--
's' is not a valid callback
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
Expand Down

0 comments on commit ea87d04

Please sign in to comment.