Skip to content

Commit 88ba9dc

Browse files
committed
ext/mbstring: Always throw ValueErrors for invalid mb_http_input() type
1 parent 5f3b4c5 commit 88ba9dc

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

UPGRADING

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ PHP 8.4 UPGRADE NOTES
3434
- MBString:
3535
. mb_encode_numericentity() and mb_decode_numericentity() now check that
3636
the $map is only composed of integers, if not a ValueError is thrown.
37+
. mb_http_input() now always throws a ValueError if the $type is invalid.
3738

3839
- PDO_DBLIB:
3940
. setAttribute, DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER and DBLIB_ATTR_DATETIME_CONVERT

ext/mbstring/mbstring.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,10 @@ PHP_FUNCTION(mb_http_input)
12711271

12721272
if (type == NULL) {
12731273
encoding = MBSTRG(http_input_identify);
1274+
} else if (type_len != 1) {
1275+
zend_argument_value_error(1,
1276+
"must be one of \"G\", \"P\", \"C\", \"S\", \"I\", or \"L\"");
1277+
RETURN_THROWS();
12741278
} else {
12751279
switch (*type) {
12761280
case 'G':

ext/mbstring/tests/mb_http_input.phpt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ var_dump(mb_http_input('C'));
2222
var_dump(mb_http_input('S'));
2323
var_dump(mb_http_input('I'));
2424
var_dump(mb_http_input('L'));
25-
try {
26-
var_dump(mb_http_input('Q'));
27-
} catch (ValueError $e) {
28-
echo $e->getMessage(), "\n";
29-
}
3025

3126
?>
3227
--EXPECT--
@@ -41,4 +36,3 @@ array(1) {
4136
string(10) "ISO-8859-1"
4237
}
4338
string(10) "ISO-8859-1"
44-
mb_http_input(): Argument #1 ($type) must be one of "G", "P", "C", "S", "I", or "L"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
mb_http_input() errors:
3+
--EXTENSIONS--
4+
mbstring
5+
--FILE--
6+
<?php
7+
8+
try {
9+
var_dump(mb_http_input('PN'));
10+
} catch (ValueError $e) {
11+
echo $e->getMessage(), "\n";
12+
}
13+
try {
14+
var_dump(mb_http_input('Q'));
15+
} catch (ValueError $e) {
16+
echo $e->getMessage(), "\n";
17+
}
18+
19+
?>
20+
--EXPECT--
21+
mb_http_input(): Argument #1 ($type) must be one of "G", "P", "C", "S", "I", or "L"
22+
mb_http_input(): Argument #1 ($type) must be one of "G", "P", "C", "S", "I", or "L"

0 commit comments

Comments
 (0)