Skip to content

Commit

Permalink
Throw on invalid mb_http_input() type
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Sep 7, 2020
1 parent ace876c commit 623bf96
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
6 changes: 3 additions & 3 deletions ext/mbstring/mbstring.c
Original file line number Diff line number Diff line change
Expand Up @@ -1377,9 +1377,9 @@ PHP_FUNCTION(mb_http_input)
mbfl_string_clear(&result);
return;
default:
// TODO ValueError
encoding = MBSTRG(http_input_identify);
break;
zend_argument_value_error(1,
"must be one of \"G\", \"P\", \"C\", \"S\", \"I\" or \"L\"");
RETURN_THROWS();
}
}

Expand Down
17 changes: 17 additions & 0 deletions ext/mbstring/tests/mb_http_input.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,27 @@ echo $_GET['b']."\n";
// Get encoding
var_dump(mb_http_input('P'));
var_dump(mb_http_input('G'));
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--
ÆüËܸì0123456789ÆüËܸ쥫¥¿¥«¥Ê¤Ò¤é¤¬¤Ê
ÆüËܸì0123456789ÆüËܸ쥫¥¿¥«¥Ê¤Ò¤é¤¬¤Ê
string(10) "ISO-8859-1"
string(10) "ISO-8859-1"
bool(false)
bool(false)
array(1) {
[0]=>
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"

0 comments on commit 623bf96

Please sign in to comment.