Skip to content
This repository has been archived by the owner on Jul 14, 2020. It is now read-only.

Commit

Permalink
Merge pull request #7 from andreasindal/empty-string-issue
Browse files Browse the repository at this point in the history
Fixed bug where trying to parse an empty string caused an exception to be thrown
  • Loading branch information
Andreas Indal authored Sep 18, 2016
2 parents 5300f10 + 4abc18a commit 5f1458f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public function __construct(Parsedown $parsedown)
*/
public function parse($markdown)
{
if (empty($markdown)) {
return '';
}

if (config('markdown.xss')) {
// Escape any XSS attempts
$markdown = preg_replace('/(\[.*\])\(javascript:.*\)/', '$1(#)', $markdown);
Expand Down
8 changes: 8 additions & 0 deletions tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ public function it_transforms_markdown_into_html()
$this->assertEquals("<h1>Hello</h1>", $html);
}

/** @test */
function it_returns_an_empty_string_when_trying_to_parse_an_empty_string()
{
$parser = new Parser(new Parsedown);

$this->assertEquals('', $parser->parse(''));
}

/** @test */
public function it_transforms_a_block_of_markdown_into_html()
{
Expand Down

0 comments on commit 5f1458f

Please sign in to comment.