]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
security: escape HTML entities when using Markdown 795/head
authorVirtualTam <virtualtam@flibidi.net>
Wed, 8 Mar 2017 19:38:41 +0000 (20:38 +0100)
committerVirtualTam <virtualtam@flibidi.net>
Wed, 8 Mar 2017 19:38:41 +0000 (20:38 +0100)
Adapted from https://github.com/shaarli/Shaarli/pull/785

Signed-off-by: VirtualTam <virtualtam@flibidi.net>
plugins/markdown/markdown.php
tests/plugins/PluginMarkdownTest.php

index 57fcce3268a6aa5c0454e97cab9a395959635e46..9d073fbdb32750ec6ca29020b7717663ca0c5e38 100644 (file)
@@ -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);
index fa7e1d52ddd1dd126ecb15f0cd1e262f7895c68a..67bf8968dfcdac199d3ed7d648e6275909b89e8c 100644 (file)
@@ -149,4 +149,22 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase
         $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']);
+    }
 }