JsonFormatterTest.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Test\Json;
  12. use Composer\Json\JsonFormatter;
  13. use Composer\Test\TestCase;
  14. class JsonFormatterTest extends TestCase
  15. {
  16. /**
  17. * Test if \u0119 will get correctly formatted (unescaped)
  18. * https://github.com/composer/composer/issues/2613
  19. */
  20. public function testUnicodeWithPrependedSlash()
  21. {
  22. if (!extension_loaded('mbstring')) {
  23. $this->markTestSkipped('Test requires the mbstring extension');
  24. }
  25. $backslash = chr(92);
  26. $data = '"' . $backslash . $backslash . $backslash . 'u0119"';
  27. $expected = '"' . $backslash . $backslash . 'ę"';
  28. $this->assertEquals($expected, JsonFormatter::format($data, true, true));
  29. }
  30. /**
  31. * Surrogate pairs are intentionally skipped and not unescaped
  32. * https://github.com/composer/composer/issues/7510
  33. */
  34. public function testUtf16SurrogatePair()
  35. {
  36. if (!extension_loaded('mbstring')) {
  37. $this->markTestSkipped('Test requires the mbstring extension');
  38. }
  39. $escaped = '"\ud83d\ude00"';
  40. $this->assertEquals($escaped, JsonFormatter::format($escaped, true, true));
  41. }
  42. }