From d9e76119105e78e1540b5116a71539a67e41594f Mon Sep 17 00:00:00 2001 From: Dan Ungureanu Date: Tue, 17 Dec 2019 18:09:29 +0200 Subject: [PATCH] FIX: Avoid String.matchAll for IE11 support --- app/assets/javascripts/discourse/lib/utilities.js.es6 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/discourse/lib/utilities.js.es6 b/app/assets/javascripts/discourse/lib/utilities.js.es6 index 7bda9ca4df..ff43ee32a1 100644 --- a/app/assets/javascripts/discourse/lib/utilities.js.es6 +++ b/app/assets/javascripts/discourse/lib/utilities.js.es6 @@ -422,17 +422,18 @@ const CODE_BLOCKS_REGEX = /^( |\t).*|`[^`]+`|^```[^]*?^```|\[code\][^]*?\[\/c // +------- paragraphs starting with 4 spaces or tab export function inCodeBlock(text, pos) { - const matches = text.matchAll(CODE_BLOCKS_REGEX); + let result = false; - for (const match of matches) { + let match; + while ((match = CODE_BLOCKS_REGEX.exec(text)) !== null) { const begin = match.index; const end = match.index + match[0].length; if (begin <= pos && pos <= end) { - return true; + result = true; } } - return false; + return result; } // This prevents a mini racer crash