ext/mbstring: Always throw ValueErrors for invalid mb_http_input() type

This commit is contained in:
Gina Peter Banyard 2023-12-07 17:23:01 +00:00
parent 5f3b4c5d6c
commit 88ba9dc61b
No known key found for this signature in database
GPG Key ID: 3306078E3194AEBD
4 changed files with 27 additions and 6 deletions

View File

@ -34,6 +34,7 @@ PHP 8.4 UPGRADE NOTES
- MBString:
. mb_encode_numericentity() and mb_decode_numericentity() now check that
the $map is only composed of integers, if not a ValueError is thrown.
. mb_http_input() now always throws a ValueError if the $type is invalid.
- PDO_DBLIB:
. setAttribute, DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER and DBLIB_ATTR_DATETIME_CONVERT

View File

@ -1271,6 +1271,10 @@ PHP_FUNCTION(mb_http_input)
if (type == NULL) {
encoding = MBSTRG(http_input_identify);
} else if (type_len != 1) {
zend_argument_value_error(1,
"must be one of \"G\", \"P\", \"C\", \"S\", \"I\", or \"L\"");
RETURN_THROWS();
} else {
switch (*type) {
case 'G':

View File

@ -22,11 +22,6 @@ var_dump(mb_http_input('C'));
var_dump(mb_http_input('S'));
var_dump(mb_http_input('I'));
var_dump(mb_http_input('L'));
try {
var_dump(mb_http_input('Q'));
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
@ -41,4 +36,3 @@ array(1) {
string(10) "ISO-8859-1"
}
string(10) "ISO-8859-1"
mb_http_input(): Argument #1 ($type) must be one of "G", "P", "C", "S", "I", or "L"

View File

@ -0,0 +1,22 @@
--TEST--
mb_http_input() errors:
--EXTENSIONS--
mbstring
--FILE--
<?php
try {
var_dump(mb_http_input('PN'));
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}
try {
var_dump(mb_http_input('Q'));
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
mb_http_input(): Argument #1 ($type) must be one of "G", "P", "C", "S", "I", or "L"
mb_http_input(): Argument #1 ($type) must be one of "G", "P", "C", "S", "I", or "L"