diff --git a/public/src/modules/translator.common.js b/public/src/modules/translator.common.js index c69a9cc265..40468f0f7a 100644 --- a/public/src/modules/translator.common.js +++ b/public/src/modules/translator.common.js @@ -464,7 +464,7 @@ module.exports = function (utils, load, warn) { */ Translator.escape = function escape(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 017efd3ce2..ccbd724cec 100644 --- a/test/translator.js +++ b/test/translator.js @@ -334,6 +334,22 @@ describe('Translator static methods', () => { ); done(); }); + + it('should escape all translation patterns within text', (done) => { + assert.strictEqual( + Translator.escape('some nice text [[global:home]] here and [[global:search]] there'), + 'some nice text [[global:home]] here and [[global:search]] there' + ); + done(); + }); + + it('should not escape markdown links', (done) => { + assert.strictEqual( + Translator.escape('[link text [test]](https://example.org)'), + '[link text [test]](https://example.org)' + ); + done(); + }); }); describe('.unescape', () => {