Skip to content

Commit c615fb0

Browse files
MrPetovancolinodell
authored andcommitted
Escape HTML entities in TextConverter::convert (#184)
* Escape HTML entities in TextConverter::convert This preserves actual HTML entities present in the text node * Update expected values to include escaped HTML entities in HtmlConverterTest
1 parent b768ada commit c615fb0

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/Converter/TextConverter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function convert(ElementInterface $element)
3535
}
3636
}
3737

38-
return $markdown;
38+
return htmlspecialchars($markdown, ENT_NOQUOTES, 'UTF-8');
3939
}
4040

4141
/**

tests/HtmlConverterTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function test_plain_text()
3535
$this->html_gives_markdown('<div>_test_</div>', '<div>_test_</div>');
3636
$this->html_gives_markdown('<div>*test*</div>', '<div>*test*</div>');
3737

38-
$this->html_gives_markdown('<p>\ ` * _ { } [ ] ( ) &gt; > # + - . !</p>', '\\\\ ` \* \_ { } \[ \] ( ) > > # + - . !');
38+
$this->html_gives_markdown('<p>\ ` * _ { } [ ] ( ) &gt; > # + - . !</p>', '\\\\ ` \* \_ { } \[ \] ( ) &gt; &gt; # + - . !');
3939
}
4040

4141
public function test_line_breaks()
@@ -271,7 +271,7 @@ public function test_remove_nodes()
271271

272272
public function test_html_entities()
273273
{
274-
$this->html_gives_markdown('<p>&amp;euro;</p>', '&euro;');
274+
$this->html_gives_markdown('<p>&amp;euro;</p>', '&amp;euro;');
275275
$this->html_gives_markdown('<code>&lt;p&gt;Some sample HTML&lt;/p&gt;</code>', '`<p>Some sample HTML</p>`');
276276
}
277277

@@ -298,14 +298,14 @@ public function test_sanitization()
298298
$html = '<pre><code>&lt;script type = "text/javascript"&gt; function startTimer() { var tim = window.setTimeout("hideMessage()", 5000) } &lt;/head&gt; &lt;body&gt;</code></pre>';
299299
$markdown = '```' . "\n" . '<script type = "text/javascript"> function startTimer() { var tim = window.setTimeout("hideMessage()", 5000) } </head> <body>' . "\n```";
300300
$this->html_gives_markdown($html, $markdown);
301-
$this->html_gives_markdown('<p>&gt; &gt; Look at me! &lt; &lt;</p>', '\> > Look at me! < <');
302-
$this->html_gives_markdown('<p>&gt; &gt; <b>Look</b> at me! &lt; &lt;<br />&gt; Just look at me!</p>', "\\> > **Look** at me! < < \n\\> Just look at me!");
301+
$this->html_gives_markdown('<p>&gt; &gt; Look at me! &lt; &lt;</p>', '&gt; &gt; Look at me! &lt; &lt;');
302+
$this->html_gives_markdown('<p>&gt; &gt; <b>Look</b> at me! &lt; &lt;<br />&gt; Just look at me!</p>', "&gt; &gt; **Look** at me! &lt; &lt; \n&gt; Just look at me!");
303303
$this->html_gives_markdown('<p>Foo<br>--<br>Bar<br>Foo--</p>', "Foo \n\\-- \nBar \nFoo--");
304304
$this->html_gives_markdown('<ul><li>Foo<br>- Bar</li></ul>', "- Foo \n \\- Bar");
305305
$this->html_gives_markdown('Foo<br />* Bar', "Foo \n\\* Bar");
306306
$this->html_gives_markdown("<p>123456789) Foo and 1234567890) Bar!</p>\n<p>1. Platz in 'Das große Backen'</p>", "123456789\\) Foo and 1234567890) Bar!\n\n1\\. Platz in 'Das große Backen'");
307307
$this->html_gives_markdown("<p>\n+ Siri works well for TV and movies<br>\n- No 4K support\n</p>", "\+ Siri works well for TV and movies \n\- No 4K support");
308-
$this->html_gives_markdown('<p>You forgot the &lt;!--more--&gt; tag!</p>', 'You forgot the \<!--more--> tag!');
308+
$this->html_gives_markdown('<p>You forgot the &lt;!--more--&gt; tag!</p>', 'You forgot the &lt;!--more--&gt; tag!');
309309
}
310310

311311
public function test_instatiation_with_environment()

0 commit comments

Comments
 (0)