Skip to content

Commit

Permalink
Test escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Dec 2, 2024
1 parent 3c285a7 commit 43d82a4
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions packages/framework/tests/Feature/MarkdownHeadingRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,41 @@ public function testHeadingsWithSpecialCharacters()
HTML, $html);
}

public function testHeadingsAllowMarkdownStyling()
{
$markdown = <<<'MARKDOWN'
## Heading with **Markdown** styling
MARKDOWN;

$html = (new MarkdownService($markdown, MarkdownPage::class))->parse();

$this->assertStringContainsString('Heading with <strong>Markdown</strong> styling', $html);

$this->assertSame(<<<'HTML'
<h2>Heading with <strong>Markdown</strong> styling</h2>

HTML, $html);
}

public function testHeadingsAllowBasicHtmlButEscapesDangerousInput()
{
$markdown = <<<'MARKDOWN'
## Heading with <strong>HTML</strong>
### Heading with <script>alert('XSS')</script>
MARKDOWN;

$html = (new MarkdownService($markdown, MarkdownPage::class))->parse();

$this->assertStringContainsString('Heading with <strong>HTML</strong>', $html);
$this->assertStringContainsString("Heading with &lt;script>alert('XSS')&lt;/script>", $html);

$this->assertSame(<<<'HTML'
<h2>Heading with <strong>HTML</strong></h2>
<h3>Heading with &lt;script>alert('XSS')&lt;/script></h3>

HTML, $html);
}

public function testCustomPageClassConfiguration()
{
config(['markdown.permalinks.pages' => [MarkdownPage::class]]);
Expand Down

0 comments on commit 43d82a4

Please sign in to comment.