Loading src/Engine/Encoder.php +1 −4 Original line number Diff line number Diff line Loading @@ -382,10 +382,7 @@ final class Encoder return; } if (str_contains($comment, '*/')) { $comment = str_replace('*/', '* /', $comment); trigger_error("Multiline comment can't contain '*/' sequence, replacing with '* /'"); } $comment = str_replace('*/', "*\u{200b}/", $comment); fwrite($this->resource, $prefix); fwrite($this->resource, '/* '); Loading tests/Formatting/NestedCommentTest.php 0 → 100644 +44 −0 Original line number Diff line number Diff line <?php declare(strict_types=1); namespace Arokettu\Json5\Tests\Formatting; use Arokettu\Json5\Json5Encoder; use Arokettu\Json5\Values\Comment; use Arokettu\Json5\Values\CommentDecorator; use Arokettu\Json5\Values\InlineObject; use PHPUnit\Framework\TestCase; class NestedCommentTest extends TestCase { public function testNoReplacementInFullSize(): void { $obj = [ 'k1' => new CommentDecorator('v1', '/* begin */', '/* end */'), new Comment('/* standalone */'), ]; self::assertEquals(<<<JSON5 { // /* begin */ k1: "v1", // /* end */ // /* standalone */ } JSON5, Json5Encoder::encode($obj)); } public function testReplacementInFullSize(): void { $obj = [ 'k1' => new CommentDecorator('v1', '/* begin */', '/* end */'), new Comment('/* standalone */'), ]; self::assertEquals(<<<JSON5 { /* /* begin *\u{200b}/ */ k1: "v1" /* /* end *\u{200b}/ */, /* /* standalone *\u{200b}/ */ } JSON5, Json5Encoder::encode(new InlineObject($obj))); } } Loading
src/Engine/Encoder.php +1 −4 Original line number Diff line number Diff line Loading @@ -382,10 +382,7 @@ final class Encoder return; } if (str_contains($comment, '*/')) { $comment = str_replace('*/', '* /', $comment); trigger_error("Multiline comment can't contain '*/' sequence, replacing with '* /'"); } $comment = str_replace('*/', "*\u{200b}/", $comment); fwrite($this->resource, $prefix); fwrite($this->resource, '/* '); Loading
tests/Formatting/NestedCommentTest.php 0 → 100644 +44 −0 Original line number Diff line number Diff line <?php declare(strict_types=1); namespace Arokettu\Json5\Tests\Formatting; use Arokettu\Json5\Json5Encoder; use Arokettu\Json5\Values\Comment; use Arokettu\Json5\Values\CommentDecorator; use Arokettu\Json5\Values\InlineObject; use PHPUnit\Framework\TestCase; class NestedCommentTest extends TestCase { public function testNoReplacementInFullSize(): void { $obj = [ 'k1' => new CommentDecorator('v1', '/* begin */', '/* end */'), new Comment('/* standalone */'), ]; self::assertEquals(<<<JSON5 { // /* begin */ k1: "v1", // /* end */ // /* standalone */ } JSON5, Json5Encoder::encode($obj)); } public function testReplacementInFullSize(): void { $obj = [ 'k1' => new CommentDecorator('v1', '/* begin */', '/* end */'), new Comment('/* standalone */'), ]; self::assertEquals(<<<JSON5 { /* /* begin *\u{200b}/ */ k1: "v1" /* /* end *\u{200b}/ */, /* /* standalone *\u{200b}/ */ } JSON5, Json5Encoder::encode(new InlineObject($obj))); } }