mirror of
https://github.com/php/php-src.git
synced 2025-08-20 09:24:05 +02:00
Return false on invalid codepoint in mb_chr()
Instead of returning the encoding of the current substitution character. This allows a robust check for the failure case. The substitution character (especially the default of "?") is also a valid output of mb_chr() for a valid input (for "?" that would be 0x3f), so it's a bad choice for an error value.
This commit is contained in:
parent
41e9ba6333
commit
e53162a32b
2 changed files with 27 additions and 46 deletions
|
@ -7,22 +7,8 @@ mb_chr()
|
|||
var_dump(
|
||||
"\u{20bb7}" === mb_chr(0x20bb7),
|
||||
"\x8f\xa1\xef" === mb_chr(0x50aa, "EUC-JP-2004"),
|
||||
"?" === mb_chr(0xd800)
|
||||
);
|
||||
|
||||
mb_internal_encoding("UCS-4BE");
|
||||
mb_substitute_character(0xfffd);
|
||||
var_dump(
|
||||
"\u{fffd}" === mb_chr(0xd800, "UTF-8")
|
||||
);
|
||||
var_dump(
|
||||
"\u{fffd}" === mb_chr(0xd800, "UTF-8")
|
||||
);
|
||||
|
||||
mb_internal_encoding("EUC-JP");
|
||||
mb_substitute_character(0xa4a2);
|
||||
var_dump(
|
||||
"\u{a4a2}" === mb_chr(0xd800, "UTF-8")
|
||||
false === mb_chr(0xd800),
|
||||
false === mb_chr(0x1f600, "EUC-JP-2004")
|
||||
);
|
||||
|
||||
// Invalid
|
||||
|
@ -39,8 +25,6 @@ bool(true)
|
|||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
|
||||
Warning: mb_chr(): Unknown encoding "typo" in %s on line %d
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue