Skip to content

Commit 659d977

Browse files
committed
ext/iconv/tests/bug48147.phpt: whitelist iconvs with //IGNORE
This test is for the behavior of iconv's magic "//IGNORE" suffix. The output it expects agrees with POSIX 2024 even when the underlying implementation (glibc) does not. A comment has been added to this effect, and two calls to urlencode() have been removed so that two (expected) errors are not swallowed. Afterwards, we whitelist the two iconv implementations that are known to support //IGNORE. While POSIX standardizes its behavior, it falls short of requiring implementations to support it. Musl in particular does not support any suffix.
1 parent 139eb4c commit 659d977

1 file changed

Lines changed: 28 additions & 4 deletions

File tree

ext/iconv/tests/bug48147.phpt

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,50 @@
22
Bug #48147 (iconv with //IGNORE cuts the string)
33
--EXTENSIONS--
44
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+
?>
519
--FILE--
620
<?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+
*/
731
$text = "aa\xC3\xC3\xC3\xB8aa";
832
var_dump(iconv("UTF-8", "UTF-8", $text));
933
var_dump(urlencode(iconv("UTF-8", "UTF-8//IGNORE", $text)));
1034
// only invalid
11-
var_dump(urlencode(iconv("UTF-8", "UTF-8//IGNORE", "\xC3")));
35+
var_dump(iconv("UTF-8", "UTF-8//IGNORE", "\xC3"));
1236
// start invalid
1337
var_dump(urlencode(iconv("UTF-8", "UTF-8//IGNORE", "\xC3\xC3\xC3\xB8aa")));
1438
// 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"));
1640
?>
1741
--EXPECTF--
1842
Notice: iconv(): Detected an illegal character in input string in %s on line %d
1943
bool(false)
2044
string(10) "aa%C3%B8aa"
2145

2246
Notice: iconv(): Detected an incomplete multibyte character in input string in %s on line %d
23-
string(0) ""
47+
bool(false)
2448
string(8) "%C3%B8aa"
2549

2650
Notice: iconv(): Detected an incomplete multibyte character in input string in %s on line %d
27-
string(0) ""
51+
bool(false)

0 commit comments

Comments
 (0)