From 1e4f0ac2160fd06cb4815460beb75abe9fd809c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Thu, 22 Aug 2019 14:47:25 +0200 Subject: [PATCH] FIX: infinite loop when mentioning in IE11 --- .../discourse-markdown/text-post-process.js.es6 | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/pretty-text/engines/discourse-markdown/text-post-process.js.es6 b/app/assets/javascripts/pretty-text/engines/discourse-markdown/text-post-process.js.es6 index 2abd120598..020545e285 100644 --- a/app/assets/javascripts/pretty-text/engines/discourse-markdown/text-post-process.js.es6 +++ b/app/assets/javascripts/pretty-text/engines/discourse-markdown/text-post-process.js.es6 @@ -81,13 +81,16 @@ function allowedBoundary(content, index, utils) { } function textPostProcess(content, state, ruler) { - let result = null, - match, - pos = 0; + let result = null; + let match; + let pos = 0; const matcher = ruler.getMatcher(); - while ((match = matcher.exec(content))) { + while (match = matcher.exec(content)) { + // something is wrong + if (match.index < pos) break; + // check boundary if (match.index > 0) { if (!allowedBoundary(content, match.index - 1, state.md.utils)) { @@ -104,15 +107,14 @@ function textPostProcess(content, state, ruler) { } } + result = result || []; + if (match.index > pos) { - result = result || []; let token = new state.Token("text", "", 0); token.content = content.slice(pos, match.index); result.push(token); } - result = result || []; - ruler.applyRule(result, match, state); pos = match.index + match[0].length;