From 806c1a0b8bad1d059aaefe4b016e35cb9f4b250f Mon Sep 17 00:00:00 2001 From: akshatdalton Date: Wed, 4 Nov 2020 21:56:09 +0000 Subject: [PATCH] markdown: Fix flickering of embedded link inside Italic. This commit fixes a bug in marked.js which caused it to double-escape HTML when rendering messages of the form: *[text](url)*. This fixes a bug introduced in 3bdc8bbaa51ced2c241da6107ec8b3604ebb2853, where an unnecessary escape() call was added for the code path, likely just because it was adjacent to the others that needed it in the file. Fix this, and add tests to verify that things are still being escaped once after removing this extra escape. Fixes #14845. --- static/third/marked/lib/marked.js | 1 - .../tests/fixtures/markdown_test_cases.json | 22 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/static/third/marked/lib/marked.js b/static/third/marked/lib/marked.js index 37795a8cd0..ebe5daf13c 100644 --- a/static/third/marked/lib/marked.js +++ b/static/third/marked/lib/marked.js @@ -1087,7 +1087,6 @@ Renderer.prototype.strong = function(text) { }; Renderer.prototype.em = function(text) { - text = escape(text); return '' + text + ''; }; diff --git a/zerver/tests/fixtures/markdown_test_cases.json b/zerver/tests/fixtures/markdown_test_cases.json index 57928a1559..d41f8c22f9 100644 --- a/zerver/tests/fixtures/markdown_test_cases.json +++ b/zerver/tests/fixtures/markdown_test_cases.json @@ -910,6 +910,28 @@ "expected_output": "
\n

header

\n
", "marked_expected_output": "
\n

header

\n
", "text_content": "header (…)\n" + }, + { + "name": "embedded_link_inside_Bold", + "input": "**[Static types in Python](https://blog.zulip.com/2016/10/13/static-types-in-python-oh-mypy)**", + "expected_output": "

Static types in Python

" + }, + { + "name": "embedded_link_inside_Italic", + "input": "*[Static types in Python](https://blog.zulip.com/2016/10/13/static-types-in-python-oh-mypy)*", + "expected_output": "

Static types in Python

" + }, + { + "name": "edge_case_embedded_link_inside_Bold", + "input": "

**

[

Static types in Python

](https://blog.zulip.com/2016/10/13/static-types-in-python-oh-mypy)**", + "expected_output": "

<h1><h1><h2>Static types in Python</h2></h1></h1>

", + "marked_expected_output": "

<h1><h1><h2>Static types in Python</h2></h1></h1>\n\n

" + }, + { + "name": "edge_case_embedded_link_inside_Italic", + "input": "

*

[

Static types in Python

](https://blog.zulip.com/2016/10/13/static-types-in-python-oh-mypy)*", + "expected_output": "

<h1><h1><h2>Static types in Python</h2></h1></h1>

", + "marked_expected_output": "

<h1><h1><h2>Static types in Python</h2></h1></h1>\n\n

" } ], "linkify_tests": [