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