xref: /PHP-7.2/ext/mbstring/tests/bug65045.phpt (revision f1d7e3ca)
1--TEST--
2Bug #65045: mb_convert_encoding breaks well-formed character
3--SKIPIF--
4<?php extension_loaded('mbstring') or die('skip mbstring not available'); ?>
5--FILE--
6<?php
7
8//declare(encoding = 'UTF-8');
9mb_internal_encoding('UTF-8');
10
11$str = "\xF0\xA4\xAD".  "\xF0\xA4\xAD\xA2"."\xF0\xA4\xAD\xA2";
12$expected = "\xEF\xBF\xBD"."\xF0\xA4\xAD\xA2"."\xF0\xA4\xAD\xA2";
13
14$str2 = "\xF0\xA4\xAD\xA2"."\xF0\xA4\xAD\xA2"."\xF0\xA4\xAD";
15$expected2 = "\xF0\xA4\xAD\xA2"."\xF0\xA4\xAD\xA2"."\xEF\xBF\xBD";
16
17mb_substitute_character(0xFFFD);
18var_dump(
19    $expected === htmlspecialchars_decode(htmlspecialchars($str, ENT_SUBSTITUTE, 'UTF-8')),
20    $expected2 === htmlspecialchars_decode(htmlspecialchars($str2, ENT_SUBSTITUTE, 'UTF-8')),
21    $expected === mb_convert_encoding($str, 'UTF-8', 'UTF-8'),
22    $expected2 === mb_convert_encoding($str2, 'UTF-8', 'UTF-8')
23);
24--EXPECT--
25bool(true)
26bool(true)
27bool(true)
28bool(true)
29