From c434262e2105617d83376ad12ac7977dad7c6f15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Fri, 8 Dec 2023 10:58:13 -0500 Subject: [PATCH] fix: change translator escape remove \\\] and \\\[ match double ] and [ --- public/src/modules/translator.common.js | 7 ++++--- test/translator.js | 4 ---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/public/src/modules/translator.common.js b/public/src/modules/translator.common.js index 49a3b59c60..c69a9cc265 100644 --- a/public/src/modules/translator.common.js +++ b/public/src/modules/translator.common.js @@ -463,7 +463,9 @@ module.exports = function (utils, load, warn) { * @returns {string} */ Translator.escape = function escape(text) { - return typeof text === 'string' ? text.replace(/\[\[/g, '[[').replace(/\]\]/g, ']]') : text; + return typeof text === 'string' ? + text.replace(/\[\[/g, '[[').replace(/\]\]/g, ']]') : + text; }; /** @@ -473,8 +475,7 @@ module.exports = function (utils, load, warn) { */ Translator.unescape = function unescape(text) { return typeof text === 'string' ? - text.replace(/[/g, '[').replace(/\\\[/g, '[') - .replace(/]/g, ']').replace(/\\\]/g, ']') : + text.replace(/]]/g, ']]').replace(/[[/g, '[[') : text; }; diff --git a/test/translator.js b/test/translator.js index 6e34012a7a..61c3d5af8e 100644 --- a/test/translator.js +++ b/test/translator.js @@ -308,10 +308,6 @@ describe('Translator static methods', () => { describe('.unescape', () => { it('should unescape escaped translation patterns within text', (done) => { - assert.strictEqual( - Translator.unescape('some nice text \\[\\[global:home\\]\\] here'), - 'some nice text [[global:home]] here' - ); assert.strictEqual( Translator.unescape('some nice text [[global:home]] here'), 'some nice text [[global:home]] here'