Skip to content

Commit

Permalink
Merge pull request #795 from virtualtam/0.7-backport/hotfix/markdown-…
Browse files Browse the repository at this point in the history
…html

security: escape HTML entities when using Markdown
  • Loading branch information
virtualtam authored Mar 8, 2017
2 parents ebd67c6 + 1328d22 commit ff6f9c7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion plugins/markdown/markdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ function process_markdown($description)
$processedDescription = reverse_space2nbsp($processedDescription);
$processedDescription = unescape($processedDescription);
$processedDescription = $parsedown
->setMarkupEscaped(false)
->setMarkupEscaped(true)
->setBreaksEnabled(true)
->text($processedDescription);
$processedDescription = sanitize_html($processedDescription);
Expand Down
18 changes: 18 additions & 0 deletions tests/plugins/PluginMarkdownTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,22 @@ function testNoMarkdownTag()
$data = hook_markdown_render_daily($data);
$this->assertEquals($str, $data['cols'][0][0]['formatedDescription']);
}

/**
* Make sure that the HTML tags are escaped.
*/
public function testMarkdownWithHtmlEscape()
{
$md = '**strong** <strong>strong</strong>';
$html = '<div class="markdown"><p><strong>strong</strong> &lt;strong&gt;strong&lt;/strong&gt;</p></div>';
$data = array(
'links' => array(
0 => array(
'description' => $md,
),
),
);
$data = hook_markdown_render_linklist($data);
$this->assertEquals($html, $data['links'][0]['description']);
}
}

0 comments on commit ff6f9c7

Please sign in to comment.