1
0
Fork 0

Added extra unit test from the example in the ticket.

pull/2718/head
Sandy Pleyte 2014-02-19 14:17:23 +01:00
parent f92f2f45a9
commit 3a2815b778
2 changed files with 19 additions and 3 deletions

View File

@ -69,9 +69,13 @@ class JsonFormatter
$buffer = preg_replace_callback('/(\\\\+)u([0-9a-f]{4})/i', function($match) {
$l = strlen($match[1]);
if ($l%2)
return str_repeat ('\\', $l-1).mb_convert_encoding(pack('H*', $match[2]), 'UTF-8', 'UCS-2BE');
if ($l % 2) {
return str_repeat('\\', $l - 1) . mb_convert_encoding(
pack('H*', $match[2]),
'UTF-8',
'UCS-2BE'
);
}
return $match[0];
}, $buffer);
}

View File

@ -198,6 +198,18 @@ class JsonFileTest extends \PHPUnit_Framework_TestCase
$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)
{
try {