]> granicus.if.org Git - php/commitdiff
Promote warning to ValueError for Spoofchecker::setRestrictionLevel()
authorGeorge Peter Banyard <girgias@php.net>
Wed, 23 Sep 2020 16:02:43 +0000 (17:02 +0100)
committerGeorge Peter Banyard <girgias@php.net>
Fri, 25 Sep 2020 16:55:31 +0000 (17:55 +0100)
Closes GH-6197

ext/intl/spoofchecker/spoofchecker_main.c
ext/intl/tests/spoofchecker_unknown_restriction_level.phpt [new file with mode: 0644]

index b04b69cb88cd7d58d19c20e40f03bd86030115f4..0d6387713e3ca1b9682371683c4e16a145ec4c79 100644 (file)
@@ -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 (file)
index 0000000..e101588
--- /dev/null
@@ -0,0 +1,17 @@
+--TEST--
+Spoofchecker attempting to pass an unknown restriction level
+--SKIPIF--
+<?php if(!extension_loaded('intl') || !class_exists("Spoofchecker")) print 'skip'; ?>
+--FILE--
+<?php
+
+$x = new Spoofchecker();
+try {
+    $x->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