Skip to content

Commit 476da42

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: ext/iconv/tests/bug52211.phpt: use per-iconv charset names (php#22543) ext/iconv/tests/bug76249.phpt: fallback for non-GNU iconv() (php#22552)
2 parents e7eebb9 + 8328868 commit 476da42

2 files changed

Lines changed: 31 additions & 6 deletions

File tree

ext/iconv/tests/bug52211.phpt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,22 @@ if (PHP_OS_FAMILY === 'Solaris') {
1111
--FILE--
1212
<?php
1313

14+
// According to POSIX 2024, the to/from charset names are
15+
// implementation-defined. To keep this test true to its original
16+
// purpose, we retain the charsets used in bug 52211, but only when
17+
// the implementation is known to support them. Otherwise we default
18+
// both to ASCII, which should be supported everywhere (in particular
19+
// on musl) yet still considers the input invalid.
20+
$from_charset = "ASCII";
21+
$to_charset = "ASCII";
22+
23+
if (ICONV_IMPL == "libiconv" || ICONV_IMPL == "glibc") {
24+
$from_charset = "CP850";
25+
$to_charset = "ISO-8859-1";
26+
}
27+
1428
$str = "PATHOLOGIES MÉDICO-CHIRUR. ADUL. PL";
15-
$str_iconv = iconv('CP850', 'ISO-8859-1', $str );
29+
$str_iconv = iconv($from_charset, $to_charset, $str );
1630
var_dump($str_iconv);
1731

1832
?>

ext/iconv/tests/bug76249.phpt

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,27 @@ Bug #76249 (stream filter convert.iconv leads to infinite loop on invalid sequen
44
iconv
55
--FILE--
66
<?php
7+
$ignore = "";
8+
if (ICONV_IMPL == "libiconv" || ICONV_IMPL == "glibc") {
9+
// The original bug report uses "//IGNORE", and the bug itself
10+
// involves the return value and errno from iconv(), so in the
11+
// interest of fidelity we include the suffix on systems like the
12+
// one where the bug was reported. On other systems however, the
13+
// "//IGNORE" suffix may not be supported, and this is allowed by
14+
// POSIX (musl in particular does not support it).
15+
$ignore = "//IGNORE";
16+
}
17+
718
$fh = fopen('php://memory', 'rw');
819
fwrite($fh, "abc");
920
rewind($fh);
10-
if (false === @stream_filter_append($fh, 'convert.iconv.ucs-2/utf8//IGNORE', STREAM_FILTER_READ, [])) {
11-
stream_filter_append($fh, 'convert.iconv.ucs-2/utf-8//IGNORE', STREAM_FILTER_READ, []);
21+
if (false === @stream_filter_append($fh, "convert.iconv.ucs-2/utf8{$ignore}", STREAM_FILTER_READ, [])) {
22+
stream_filter_append($fh, "convert.iconv.ucs-2/utf-8{$ignore}", STREAM_FILTER_READ, []);
1223
}
1324
var_dump(stream_get_contents($fh));
1425
?>
1526
DONE
16-
--EXPECTF--
17-
Warning: stream_get_contents(): iconv stream filter ("ucs-2"=>"utf%A8//IGNORE"): invalid multibyte sequence in %sbug76249.php on line %d
18-
string(0) ""
27+
--EXPECTREGEX--
28+
Warning: stream_get_contents\(\): iconv stream filter \("ucs-2"=>"utf-?8(\/\/IGNORE)?"\): invalid multibyte sequence in .*bug76249\.php on line \d+
29+
string\(0\) ""
1930
DONE

0 commit comments

Comments
 (0)