From fde30577e4b370cf952338f058085ef65ef54972 Mon Sep 17 00:00:00 2001 From: BobVul Date: Fri, 31 Jan 2020 12:33:10 +1100 Subject: [PATCH] Fix escaped markdown passing backslashes through Fixes https://github.com/vector-im/riot-web/issues/11230 Signed-off-by: Bob Rao --- src/editor/serialize.js | 4 ++++ test/editor/serialize-test.js | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/src/editor/serialize.js b/src/editor/serialize.js index ba380f2809..075c462b37 100644 --- a/src/editor/serialize.js +++ b/src/editor/serialize.js @@ -41,6 +41,10 @@ export function htmlSerializeIfNeeded(model, {forceHTML = false} = {}) { if (!parser.isPlainText() || forceHTML) { return parser.toHTML(); } + // Format "plain" text to ensure removal of backslash escapes + // https://github.com/vector-im/riot-web/issues/11230 + // https://github.com/vector-im/riot-web/issues/2870 + return parser.toPlaintext(); } export function textSerialize(model) { diff --git a/test/editor/serialize-test.js b/test/editor/serialize-test.js index 7517e46437..f846e0d79e 100644 --- a/test/editor/serialize-test.js +++ b/test/editor/serialize-test.js @@ -43,4 +43,10 @@ describe('editor/serialize', function() { const html = htmlSerializeIfNeeded(model, {}); expect(html).toBe("hello world"); }); + it('escaped markdown should not retain backslashes', function() { + const pc = createPartCreator(); + const model = new EditorModel([pc.plain('\\*hello\\* world')]); + const html = htmlSerializeIfNeeded(model, {}); + expect(html).toBe('*hello* world'); + }) });