Skip to content

Commit efdfba4

Browse files
committed
ext/intl: report argument #3 ($variant) for an invalid IDNA variant
php_intl_idn_handoff() takes domain, flags, variant, so the variant check must report argument 3; it hardcodes 2, which makes idn_to_ascii() and idn_to_utf8() blame $flags for a value carried by $variant.
1 parent 759829b commit efdfba4

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

ext/intl/idn/idn.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ static void php_intl_idn_handoff(INTERNAL_FUNCTION_PARAMETERS, int mode)
126126
RETURN_THROWS();
127127
}
128128
if (variant != INTL_IDN_VARIANT_UTS46) {
129-
zend_argument_value_error(2, "must be INTL_IDNA_VARIANT_UTS46");
129+
zend_argument_value_error(3, "must be INTL_IDNA_VARIANT_UTS46");
130130
RETURN_THROWS();
131131
}
132132
/* don't check options; it wasn't checked before */

ext/intl/tests/idn_uts46_errors.phpt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ try {
1818
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
1919
}
2020

21+
echo "bad variant, named argument:", "\n";
22+
try {
23+
var_dump(idn_to_utf8("xn--fuball-cta.com", variant: INTL_IDNA_VARIANT_UTS46 + 10));
24+
} catch (Throwable $e) {
25+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
26+
}
27+
2128
echo "empty domain:", "\n";
2229
try {
2330
var_dump(idn_to_ascii("", 0, INTL_IDNA_VARIANT_UTS46));
@@ -45,7 +52,9 @@ var_dump($foo["errors"]==IDNA_ERROR_CONTEXTJ);
4552
--EXPECT--
4653
=> PHP level errors
4754
bad variant:
48-
ValueError: idn_to_ascii(): Argument #2 ($flags) must be INTL_IDNA_VARIANT_UTS46
55+
ValueError: idn_to_ascii(): Argument #3 ($variant) must be INTL_IDNA_VARIANT_UTS46
56+
bad variant, named argument:
57+
ValueError: idn_to_utf8(): Argument #3 ($variant) must be INTL_IDNA_VARIANT_UTS46
4958
empty domain:
5059
ValueError: idn_to_ascii(): Argument #1 ($domain) must not be empty
5160
with error, but no details arg:

0 commit comments

Comments
 (0)