From e505e3699121bcc5b8d0b54347eb6681d27964d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Fri, 16 Jan 2026 13:17:02 -0500 Subject: [PATCH] fix: make translator.unescape stricter like escape --- public/src/modules/translator.common.js | 2 +- test/translator.js | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/public/src/modules/translator.common.js b/public/src/modules/translator.common.js index 40468f0f7a..8f78c5c49e 100644 --- a/public/src/modules/translator.common.js +++ b/public/src/modules/translator.common.js @@ -475,7 +475,7 @@ module.exports = function (utils, load, warn) { */ Translator.unescape = function unescape(text) { return typeof text === 'string' ? - text.replace(/]]/g, ']]').replace(/[[/g, '[[') : + text.replace(/[[([a-zA-Z0-9_.-]+:[a-zA-Z0-9_.-]+)]]/g, '[[$1]]') : text; }; diff --git a/test/translator.js b/test/translator.js index ccbd724cec..04d11112d5 100644 --- a/test/translator.js +++ b/test/translator.js @@ -326,7 +326,7 @@ describe('Translator static methods', () => { done(); }); }); - describe('.escape', () => { + describe('.escape/.unescape', () => { it('should escape translation patterns within text', (done) => { assert.strictEqual( Translator.escape('some nice text [[global:home]] here'), @@ -350,9 +350,7 @@ describe('Translator static methods', () => { ); done(); }); - }); - describe('.unescape', () => { it('should unescape escaped translation patterns within text', (done) => { assert.strictEqual( Translator.unescape('some nice text [[global:home]] here'), @@ -360,6 +358,14 @@ describe('Translator static methods', () => { ); done(); }); + + it('should not unescape markdown links', (done) => { + assert.strictEqual( + Translator.unescape('&lsqblink text &lsqbtest]](https://example.org)'), + '&lsqblink text &lsqbtest]](https://example.org)' + ); + done(); + }); }); describe('.compile', () => {