Added extra unit test from the example in the ticket.
parent
f92f2f45a9
commit
3a2815b778
|
@ -69,9 +69,13 @@ class JsonFormatter
|
||||||
$buffer = preg_replace_callback('/(\\\\+)u([0-9a-f]{4})/i', function($match) {
|
$buffer = preg_replace_callback('/(\\\\+)u([0-9a-f]{4})/i', function($match) {
|
||||||
$l = strlen($match[1]);
|
$l = strlen($match[1]);
|
||||||
|
|
||||||
if ($l%2)
|
if ($l % 2) {
|
||||||
return str_repeat ('\\', $l-1).mb_convert_encoding(pack('H*', $match[2]), 'UTF-8', 'UCS-2BE');
|
return str_repeat('\\', $l - 1) . mb_convert_encoding(
|
||||||
|
pack('H*', $match[2]),
|
||||||
|
'UTF-8',
|
||||||
|
'UCS-2BE'
|
||||||
|
);
|
||||||
|
}
|
||||||
return $match[0];
|
return $match[0];
|
||||||
}, $buffer);
|
}, $buffer);
|
||||||
}
|
}
|
||||||
|
|
|
@ -198,6 +198,18 @@ class JsonFileTest extends \PHPUnit_Framework_TestCase
|
||||||
$this->assertJsonFormat('"\\u018c"', $data, 0);
|
$this->assertJsonFormat('"\\u018c"', $data, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDoubleEscapedUnicode()
|
||||||
|
{
|
||||||
|
$jsonFile = new JsonFile('composer.json');
|
||||||
|
$data = array("Zdjęcia","hjkjhl\\u0119kkjk");
|
||||||
|
$encodedData = $jsonFile->encode($data);
|
||||||
|
$doubleEncodedData = $jsonFile->encode(array('t' => $encodedData));
|
||||||
|
|
||||||
|
$decodedData = json_decode($doubleEncodedData, true);
|
||||||
|
$doubleData = json_decode($decodedData['t'], true);
|
||||||
|
$this->assertEquals($data, $doubleData);
|
||||||
|
}
|
||||||
|
|
||||||
private function expectParseException($text, $json)
|
private function expectParseException($text, $json)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue