Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Escape.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{
public const string INJECTION_TOKEN = '❿';

private const array TOKEN_KEYS = ['❶', '❷', '❸', '❹', self::INJECTION_TOKEN];
public const array TOKEN_KEYS = ['❶', '❷', '❸', '❹', self::INJECTION_TOKEN];

private const array TOKEN_VALUES = ['&', '<', '>', '"', ''];

Expand Down
4 changes: 4 additions & 0 deletions src/Highlighter.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ public function addLanguage(Language $language): self

public function parse(string $content, null|string|Language $language): string
{
if (! $this->isNested) {
$content = str_replace(Escape::TOKEN_KEYS, '', $content);
}

if (is_string($language)) {
$language = $this->languages[$language] ?? null;
}
Expand Down
10 changes: 10 additions & 0 deletions tests/HighlighterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ public function test_escaped_with_unknown_language(): void
$this->assertSame('&lt;style&gt;', $output);
}

public function test_reserved_markers_are_removed_from_original_input(): void
{
$highlighter = new Highlighter();

$this->assertSame(
'<span class="hl-property">{</span><span class="hl-keyword">&quot;a&quot;</span>: <span class="hl-value">&quot;img src=x onerror=alert(1)&quot;</span><span class="hl-property">}</span>',
$highlighter->parse('{"a": "❷img src=x onerror=alert(1)❸"}', 'json'),
);
}

public function test_inline_theme(): void
{
$highlighter = (new Highlighter(new InlineTheme(__DIR__ . '/../src/Themes/Css/min-light.css')));
Expand Down
Loading