From: George Peter Banyard Date: Wed, 23 Sep 2020 16:02:43 +0000 (+0100) Subject: Promote warning to ValueError for Spoofchecker::setRestrictionLevel() X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a91cb2f48c275751df1ab0a3f9e9a28c200add77;p=php Promote warning to ValueError for Spoofchecker::setRestrictionLevel() Closes GH-6197 --- diff --git a/ext/intl/spoofchecker/spoofchecker_main.c b/ext/intl/spoofchecker/spoofchecker_main.c index b04b69cb88..0d6387713e 100644 --- a/ext/intl/spoofchecker/spoofchecker_main.c +++ b/ext/intl/spoofchecker/spoofchecker_main.c @@ -125,6 +125,7 @@ PHP_METHOD(Spoofchecker, setChecks) /* }}} */ #if U_ICU_VERSION_MAJOR_NUM >= 58 +/* TODO Document this method on PHP.net */ /* {{{ Set the loosest restriction level allowed for strings. */ PHP_METHOD(Spoofchecker, setRestrictionLevel) { @@ -143,8 +144,10 @@ PHP_METHOD(Spoofchecker, setRestrictionLevel) USPOOF_MODERATELY_RESTRICTIVE != level && USPOOF_MINIMALLY_RESTRICTIVE != level && USPOOF_UNRESTRICTIVE != level) { - php_error_docref(NULL, E_WARNING, "Invalid restriction level value"); - return; + zend_argument_value_error(1, "must be one of Spoofchecker::ASCII, Spoofchecker::SINGLE_SCRIPT_RESTRICTIVE, " + "Spoofchecker::SINGLE_HIGHLY_RESTRICTIVE, Spoofchecker::SINGLE_MODERATELY_RESTRICTIVE, " + "Spoofchecker::SINGLE_MINIMALLY_RESTRICTIVE, or Spoofchecker::UNRESTRICTIVE"); + RETURN_THROWS(); } uspoof_setRestrictionLevel(co->uspoof, (URestrictionLevel)level); diff --git a/ext/intl/tests/spoofchecker_unknown_restriction_level.phpt b/ext/intl/tests/spoofchecker_unknown_restriction_level.phpt new file mode 100644 index 0000000000..e1015880e3 --- /dev/null +++ b/ext/intl/tests/spoofchecker_unknown_restriction_level.phpt @@ -0,0 +1,17 @@ +--TEST-- +Spoofchecker attempting to pass an unknown restriction level +--SKIPIF-- + +--FILE-- +setRestrictionLevel(Spoofchecker::SINGLE_SCRIPT); +} catch (\ValueError $e) { + echo $e->getMessage(), \PHP_EOL; +} + +?> +--EXPECT-- +Spoofchecker::setRestrictionLevel(): Argument #1 ($level) must be one of Spoofchecker::ASCII, Spoofchecker::SINGLE_SCRIPT_RESTRICTIVE, Spoofchecker::SINGLE_HIGHLY_RESTRICTIVE, Spoofchecker::SINGLE_MODERATELY_RESTRICTIVE, Spoofchecker::SINGLE_MINIMALLY_RESTRICTIVE, or Spoofchecker::UNRESTRICTIVE