Skip to content

Commit 229dff9

Browse files
committed
Promote unsupported encoding warnings to ValueError
1 parent 21227dc commit 229dff9

File tree

4 files changed

+36
-38
lines changed

4 files changed

+36
-38
lines changed

ext/mbstring/mbstring.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4304,7 +4304,7 @@ PHP_FUNCTION(mb_check_encoding)
43044304
RETURN_THROWS();
43054305
}
43064306
if (encoding == &mbfl_encoding_pass) {
4307-
zend_argument_value_error(2, "cannot check \"pass\" encoding");
4307+
zend_value_error("mb_check_encoding() does not support the \"pass\" encoding");
43084308
RETURN_THROWS();
43094309
}
43104310

@@ -4342,8 +4342,8 @@ static inline zend_long php_mb_ord(const char *str, size_t str_len, zend_string
43424342

43434343
no_enc = enc->no_encoding;
43444344
if (php_mb_is_unsupported_no_encoding(no_enc)) {
4345-
php_error_docref(NULL, E_WARNING, "Unsupported encoding \"%s\"", enc->name);
4346-
return -1;
4345+
zend_value_error("mb_ord() does not support the \"%s\" encoding", enc->name);
4346+
return -2;
43474347
}
43484348

43494349
if (str_len == 0) {
@@ -4425,7 +4425,7 @@ static inline zend_string *php_mb_chr(zend_long cp, zend_string *enc_name, uint3
44254425

44264426
no_enc = enc->no_encoding;
44274427
if (php_mb_is_unsupported_no_encoding(no_enc)) {
4428-
php_error_docref(NULL, E_WARNING, "Unsupported encoding \"%s\"", ZSTR_VAL(enc_name));
4428+
zend_value_error("mb_chr() does not support the \"%s\" encoding", enc->name);
44294429
return NULL;
44304430
}
44314431

ext/mbstring/tests/mb_check_encoding_invalid_encodings.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ Using "BAD" as encoding
3838
mb_check_encoding(): Argument #2 ($encoding) must be a valid encoding, "BAD" given
3939
mb_check_encoding(): Argument #2 ($encoding) must be a valid encoding, "BAD" given
4040
Using "pass" as encoding
41-
mb_check_encoding(): Argument #2 ($encoding) cannot check "pass" encoding
42-
mb_check_encoding(): Argument #2 ($encoding) cannot check "pass" encoding
41+
mb_check_encoding() does not support the "pass" encoding
42+
mb_check_encoding() does not support the "pass" encoding

ext/mbstring/tests/mb_chr.phpt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,22 @@ try {
3838
echo $e->getMessage() . \PHP_EOL;
3939
}
4040

41+
mb_internal_encoding("utf-7");
42+
try {
43+
var_dump( mb_chr(0xd800) );
44+
} catch (\ValueError $e) {
45+
echo $e->getMessage() . \PHP_EOL;
46+
}
47+
4148
?>
42-
--EXPECTF--
49+
--EXPECT--
4350
bool(true)
4451
bool(true)
4552
bool(true)
4653
bool(true)
4754
mb_chr(): Argument #2 ($encoding) must be a valid encoding, "typo" given
48-
49-
Warning: mb_chr(): Unsupported encoding "pass" in %s on line %d
50-
bool(false)
51-
52-
Warning: mb_chr(): Unsupported encoding "jis" in %s on line %d
53-
bool(false)
54-
55-
Warning: mb_chr(): Unsupported encoding "cp50222" in %s on line %d
56-
bool(false)
57-
58-
Warning: mb_chr(): Unsupported encoding "utf-7" in %s on line %d
59-
bool(false)
55+
mb_chr() does not support the "pass" encoding
56+
mb_chr() does not support the "JIS" encoding
57+
mb_chr() does not support the "CP50222" encoding
58+
mb_chr() does not support the "UTF-7" encoding
59+
mb_chr() does not support the "UTF-7" encoding

ext/mbstring/tests/mb_ord.phpt

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ var_dump(
1010
0x50aa === mb_ord("\x8f\xa1\xef", "EUC-JP-2004")
1111
);
1212

13+
// Empty string
14+
try {
15+
var_dump( mb_ord("") );
16+
} catch (\ValueError $e) {
17+
echo $e->getMessage() . \PHP_EOL;
18+
}
19+
1320
// Invalid
1421
try {
1522
var_dump( mb_ord("\u{d800}", "typo") );
@@ -36,34 +43,25 @@ try {
3643
} catch (\ValueError $e) {
3744
echo $e->getMessage() . \PHP_EOL;
3845
}
46+
47+
mb_internal_encoding("utf-7");
3948
try {
40-
var_dump( mb_ord("") );
49+
var_dump( mb_ord("\u{d800}") );
4150
} catch (\ValueError $e) {
4251
echo $e->getMessage() . \PHP_EOL;
4352
}
44-
45-
mb_internal_encoding("utf-7");
46-
mb_ord("");
53+
;
4754
?>
4855
--EXPECTF--
4956
bool(true)
5057
bool(true)
5158
bool(true)
52-
mb_ord(): Argument #2 ($encoding) must be a valid encoding, "typo" given
53-
54-
Warning: mb_ord(): Unsupported encoding "pass" in %s on line %d
55-
bool(false)
56-
57-
Warning: mb_ord(): Unsupported encoding "JIS" in %s on line %d
58-
bool(false)
59-
60-
Warning: mb_ord(): Unsupported encoding "CP50222" in %s on line %d
61-
bool(false)
62-
63-
Warning: mb_ord(): Unsupported encoding "UTF-7" in %s on line %d
64-
bool(false)
6559

6660
Warning: mb_ord(): Empty string in %s on line %d
6761
bool(false)
68-
69-
Warning: mb_ord(): Unsupported encoding "UTF-7" in %s on line %d
62+
mb_ord(): Argument #2 ($encoding) must be a valid encoding, "typo" given
63+
mb_ord() does not support the "pass" encoding
64+
mb_ord() does not support the "JIS" encoding
65+
mb_ord() does not support the "CP50222" encoding
66+
mb_ord() does not support the "UTF-7" encoding
67+
mb_ord() does not support the "UTF-7" encoding

0 commit comments

Comments
 (0)