1
0
mirror of https://github.com/erusev/parsedown.git synced 2023-08-10 21:13:06 +03:00

Still grab the text if safe mode enabled, but output it escaped

This commit is contained in:
Aidan Woods 2018-03-15 11:09:55 +00:00
parent e4c5be026d
commit ef7ed7b66c
No known key found for this signature in database
GPG Key ID: 9A6A8EFAA512BBB9
2 changed files with 8 additions and 1 deletions

View File

@ -1495,9 +1495,10 @@ class Parsedown
} }
// very strongly consider an alternative if you're writing an // very strongly consider an alternative if you're writing an
// extension // extension
elseif (isset($Element['unsafeHtml']) and !$this->safeMode) elseif (isset($Element['unsafeHtml']))
{ {
$text = $Element['unsafeHtml']; $text = $Element['unsafeHtml'];
$unsafeHtml = true; $unsafeHtml = true;
} }

View File

@ -60,11 +60,17 @@ class ParsedownTest extends TestCase
{ {
$markdown = "```php\nfoobar\n```"; $markdown = "```php\nfoobar\n```";
$expectedMarkup = '<pre><code class="language-php"><p>foobar</p></code></pre>'; $expectedMarkup = '<pre><code class="language-php"><p>foobar</p></code></pre>';
$expectedSafeMarkup = '<pre><code class="language-php">&lt;p&gt;foobar&lt;/p&gt;</code></pre>';
$unsafeExtension = new UnsafeExtension; $unsafeExtension = new UnsafeExtension;
$actualMarkup = $unsafeExtension->text($markdown); $actualMarkup = $unsafeExtension->text($markdown);
$this->assertEquals($expectedMarkup, $actualMarkup); $this->assertEquals($expectedMarkup, $actualMarkup);
$unsafeExtension->setSafeMode(true);
$actualSafeMarkup = $unsafeExtension->text($markdown);
$this->assertEquals($expectedSafeMarkup, $actualSafeMarkup);
} }
function data() function data()