From 0b2f72db921bf13818bbb140bc874b7879825848 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Wed, 5 May 2021 12:38:48 +0200 Subject: [PATCH] advanced syntaxes: yet another regression fixed --- src/client/widgets/utils.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/client/widgets/utils.js b/src/client/widgets/utils.js index 47a62cd7..848f07bf 100644 --- a/src/client/widgets/utils.js +++ b/src/client/widgets/utils.js @@ -119,24 +119,30 @@ module.exports = { balancedReplace(tag, open, close, string, replacement) { - var start + var start, lastStart = -1 - while ((start = string.indexOf(tag + open)) >= 0) { + while ((start = string.indexOf(tag + open)) >= 0 && lastStart !== start) { var substring = string.slice(start + tag.length), b = balanced(open, close, substring) - if (typeof replacement === 'function') { + if (b) { - substring = b.pre + replacement(b.body) + b.post + if (typeof replacement === 'function') { - } else { + substring = b.pre + replacement(b.body) + b.post - substring = b.pre + replacement + b.post + } else { + + substring = b.pre + replacement + b.post + + } + + string = string.slice(0, start) + substring } - string = string.slice(0, start) + substring + lastStart = start }