xref: /PHP-8.2/ext/mbstring/tests/bug69079.phpt (revision 39131219)
1--TEST--
2Bug #69079 (enhancement for mb_substitute_character)
3--EXTENSIONS--
4mbstring
5--FILE--
6<?php
7
8mb_internal_encoding('UTF-8');
9var_dump(mb_substitute_character(0x1F600));
10var_dump(bin2hex(mb_scrub("\xff")));
11mb_substitute_character(0x3f); // Reset to '?', as the next call will fail
12try {
13    var_dump(mb_substitute_character(0xD800)); // Surrogate (illegal)
14} catch (\ValueError $e) {
15    echo $e->getMessage() . \PHP_EOL;
16}
17var_dump(bin2hex(mb_scrub("\xff")));
18
19mb_internal_encoding('EUC-JP-2004');
20
21mb_substitute_character(0x63); // Reset to '?', as the next call will fail
22try {
23    mb_substitute_character(0x8fa1ef); // EUC-JP-2004 encoding of U+50AA (illegal)
24} catch (\ValueError $e) {
25    echo $e->getMessage() . \PHP_EOL;
26}
27var_dump(bin2hex(mb_scrub("\x8d")));
28
29mb_substitute_character(0x50aa);
30var_dump(bin2hex(mb_scrub("\x8d")));
31
32?>
33--EXPECT--
34bool(true)
35string(8) "f09f9880"
36mb_substitute_character(): Argument #1 ($substitute_character) is not a valid codepoint
37string(2) "3f"
38mb_substitute_character(): Argument #1 ($substitute_character) is not a valid codepoint
39string(2) "63"
40string(6) "8fa1ef"
41