Skip to content

Commit 80db0a0

Browse files
committed
Fix HTML special chars in JSON renderer should be escaped
Signed-off-by: Jack Cherng <[email protected]>
1 parent 09a405e commit 80db0a0

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/Renderer/Html/AbstractHtml.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,6 @@ protected function getDefaultBlock(string $tag, int $i1, int $j1): array
186186
*/
187187
protected function formatLines(array $lines): array
188188
{
189-
// for example, the "Json" template does not need these
190-
if (static::IS_TEXT_TEMPLATE) {
191-
return $lines;
192-
}
193-
194189
// glue all lines into a single string to get rid of multiple function calls later
195190
// unnecessary, but should improve performance if there are many lines
196191
$string = \implode(RendererConstant::IMPLODE_DELIMITER, $lines);

src/Renderer/Html/Json.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace Jfcherng\Diff\Renderer\Html;
66

7+
use Jfcherng\Diff\Renderer\RendererConstant;
8+
79
/**
810
* Json diff generator.
911
*/
@@ -36,4 +38,19 @@ public function render(): string
3638
\JSON_UNESCAPED_UNICODE | \JSON_UNESCAPED_SLASHES
3739
);
3840
}
41+
42+
/**
43+
* {@inheritdoc}
44+
*/
45+
protected function formatLines(array $lines): array
46+
{
47+
// glue all lines into a single string to get rid of multiple function calls later
48+
// unnecessary, but should improve performance if there are many lines
49+
$string = \implode(RendererConstant::IMPLODE_DELIMITER, $lines);
50+
51+
$string = $this->htmlSafe($string);
52+
53+
// split the string back to lines
54+
return \explode(RendererConstant::IMPLODE_DELIMITER, $string);
55+
}
3956
}

0 commit comments

Comments
 (0)