|
2 | 2 | Bug #48147 (iconv with //IGNORE cuts the string) |
3 | 3 | --EXTENSIONS-- |
4 | 4 | iconv |
| 5 | +--SKIPIF-- |
| 6 | +<?php |
| 7 | +/* |
| 8 | + * POSIX 2024 specifies how the "//IGNORE" suffix should behave, but |
| 9 | + * falls short of requiring implementations to support it (iconv_open |
| 10 | + * is allowed to return EINVAL for a suffix it does not recognize). |
| 11 | + * |
| 12 | + * Many implementations still do not support it, which is OK. We |
| 13 | + * whitelist the ones that are known to. |
| 14 | + */ |
| 15 | +if (ICONV_IMPL != "glibc" && ICONV_IMPL != "libiconv") { |
| 16 | + die("skip iconv implementation may not support //IGNORE"); |
| 17 | +} |
| 18 | +?> |
5 | 19 | --FILE-- |
6 | 20 | <?php |
| 21 | +/* |
| 22 | + * POSIX says that when //IGNORE is specified, invalid bytes followed |
| 23 | + * by valid bytes "shall not be treated as an error." GNU iconv does |
| 24 | + * not follow this convention, but PHP does the right thing. In the |
| 25 | + * examples below, invalid bytes in the middle of the string get |
| 26 | + * dropped, and a string is returned. The two examples where the |
| 27 | + * problem is at the end do not qualify for the "shall not" exception |
| 28 | + * because there are no VALID bytes after the error. So PHP is morally |
| 29 | + * correct in those cases to return an error (false). |
| 30 | + */ |
7 | 31 | $text = "aa\xC3\xC3\xC3\xB8aa"; |
8 | 32 | var_dump(iconv("UTF-8", "UTF-8", $text)); |
9 | 33 | var_dump(urlencode(iconv("UTF-8", "UTF-8//IGNORE", $text))); |
10 | 34 | // only invalid |
11 | | -var_dump(urlencode(iconv("UTF-8", "UTF-8//IGNORE", "\xC3"))); |
| 35 | +var_dump(iconv("UTF-8", "UTF-8//IGNORE", "\xC3")); |
12 | 36 | // start invalid |
13 | 37 | var_dump(urlencode(iconv("UTF-8", "UTF-8//IGNORE", "\xC3\xC3\xC3\xB8aa"))); |
14 | 38 | // finish invalid |
15 | | -var_dump(urlencode(iconv("UTF-8", "UTF-8//IGNORE", "aa\xC3\xC3\xC3"))); |
| 39 | +var_dump(iconv("UTF-8", "UTF-8//IGNORE", "aa\xC3\xC3\xC3")); |
16 | 40 | ?> |
17 | 41 | --EXPECTF-- |
18 | 42 | Notice: iconv(): Detected an illegal character in input string in %s on line %d |
19 | 43 | bool(false) |
20 | 44 | string(10) "aa%C3%B8aa" |
21 | 45 |
|
22 | 46 | Notice: iconv(): Detected an incomplete multibyte character in input string in %s on line %d |
23 | | -string(0) "" |
| 47 | +bool(false) |
24 | 48 | string(8) "%C3%B8aa" |
25 | 49 |
|
26 | 50 | Notice: iconv(): Detected an incomplete multibyte character in input string in %s on line %d |
27 | | -string(0) "" |
| 51 | +bool(false) |
0 commit comments