xref: /PHP-8.1/ext/mbstring/tests/bug79149.phpt (revision 74859783)
1--TEST--
2Bug #79149 (SEGV in mb_convert_encoding with non-string encodings)
3--EXTENSIONS--
4mbstring
5--FILE--
6<?php
7try {
8    var_dump(mb_convert_encoding("", "UTF-8", [0]));
9} catch (\ValueError $e) {
10    echo $e->getMessage() . \PHP_EOL;
11}
12try {
13    var_dump(mb_convert_encoding('foo', 'UTF-8', array(['bar'], ['baz'])));
14} catch (\ValueError $e) {
15    echo $e->getMessage() . \PHP_EOL;
16}
17try {
18    var_dump(mb_convert_encoding('foo', 'UTF-8', array("foo\0bar")));
19} catch (\ValueError $e) {
20    echo $e->getMessage() . \PHP_EOL;
21}
22
23?>
24--EXPECTF--
25mb_convert_encoding(): Argument #3 ($from_encoding) contains invalid encoding "0"
26
27Warning: Array to string conversion in %s on line %d
28mb_convert_encoding(): Argument #3 ($from_encoding) contains invalid encoding "Array"
29mb_convert_encoding(): Argument #3 ($from_encoding) contains invalid encoding "foo"
30