Promote empty string warning to ValueError in mb_ord()

This commit is contained in:
George Peter Banyard 2020-04-02 18:35:20 +02:00
parent cf3528bd44
commit 4cd3d7b166
2 changed files with 13 additions and 13 deletions

View file

@ -4335,6 +4335,8 @@ static inline zend_long php_mb_ord(const char *str, size_t str_len, zend_string
const mbfl_encoding *enc;
enum mbfl_no_encoding no_enc;
ZEND_ASSERT(str_len > 0);
enc = php_mb_get_encoding(enc_name, enc_name_arg_num);
if (!enc) {
return -2;
@ -4346,11 +4348,6 @@ static inline zend_long php_mb_ord(const char *str, size_t str_len, zend_string
return -2;
}
if (str_len == 0) {
php_error_docref(NULL, E_WARNING, "Empty string");
return -1;
}
{
mbfl_wchar_device dev;
mbfl_convert_filter *filter;
@ -4396,6 +4393,11 @@ PHP_FUNCTION(mb_ord)
Z_PARAM_STR(enc)
ZEND_PARSE_PARAMETERS_END();
if (str_len == 0) {
zend_argument_value_error(1, "must not be empty");
RETURN_THROWS();
}
cp = php_mb_ord(str, str_len, enc, 2);
if (0 > cp) {

View file

@ -50,15 +50,13 @@ try {
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}
;
?>
--EXPECTF--
bool(true)
bool(true)
bool(true)
Warning: mb_ord(): Empty string in %s on line %d
bool(false)
?>
--EXPECT--
bool(true)
bool(true)
bool(true)
mb_ord(): Argument #1 ($str) must not be empty
mb_ord(): Argument #2 ($encoding) must be a valid encoding, "typo" given
mb_ord() does not support the "pass" encoding
mb_ord() does not support the "JIS" encoding