2014-02-18 08:01:12 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Composer.
|
|
|
|
*
|
|
|
|
* (c) Nils Adermann <naderman@naderman.de>
|
|
|
|
* Jordi Boggiano <j.boggiano@seld.be>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Composer\Test\Json;
|
|
|
|
|
|
|
|
use Composer\Json\JsonFormatter;
|
2017-11-04 14:52:13 +00:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2014-02-18 08:01:12 +00:00
|
|
|
|
2017-11-04 14:52:13 +00:00
|
|
|
class JsonFormatterTest extends TestCase
|
2014-02-18 08:01:12 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test if \u0119 (196+153) will get correctly formatted
|
|
|
|
* See ticket #2613
|
|
|
|
*/
|
|
|
|
public function testUnicodeWithPrependedSlash()
|
|
|
|
{
|
2014-03-06 09:26:16 +00:00
|
|
|
if (!extension_loaded('mbstring')) {
|
|
|
|
$this->markTestSkipped('Test requires the mbstring extension');
|
|
|
|
}
|
2014-03-06 01:30:09 +00:00
|
|
|
|
2014-02-18 08:01:12 +00:00
|
|
|
$data = '"' . chr(92) . chr(92) . chr(92) . 'u0119"';
|
|
|
|
$encodedData = JsonFormatter::format($data, true, true);
|
|
|
|
$expected = '34+92+92+196+153+34';
|
|
|
|
$this->assertEquals($expected, $this->getCharacterCodes($encodedData));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert string to character codes split by a plus sign
|
2014-06-10 14:02:44 +00:00
|
|
|
* @param string $string
|
2014-02-18 08:01:12 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function getCharacterCodes($string)
|
|
|
|
{
|
|
|
|
$codes = array();
|
|
|
|
for ($i = 0; $i < strlen($string); $i++) {
|
|
|
|
$codes[] = ord($string[$i]);
|
|
|
|
}
|
2014-06-10 14:02:44 +00:00
|
|
|
|
2014-02-18 08:01:12 +00:00
|
|
|
return implode('+', $codes);
|
|
|
|
}
|
|
|
|
}
|