fix: closes #13887, make translator.escape stricter

only match [[namespace:key]] allow underscores,dashes and dots in namespace key
add test
This commit is contained in:
Barış Soner Uşaklı
2026-01-16 13:00:41 -05:00
parent 918bb04491
commit b2fa7304e9
2 changed files with 17 additions and 1 deletions

View File

@@ -464,7 +464,7 @@ module.exports = function (utils, load, warn) {
*/ */
Translator.escape = function escape(text) { Translator.escape = function escape(text) {
return typeof text === 'string' ? return typeof text === 'string' ?
text.replace(/\[\[/g, '[[').replace(/\]\]/g, ']]') : text.replace(/\[\[([a-zA-Z0-9_.-]+:[a-zA-Z0-9_.-]+)\]\]/g, '[[$1]]') :
text; text;
}; };

View File

@@ -334,6 +334,22 @@ describe('Translator static methods', () => {
); );
done(); 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', () => { describe('.unescape', () => {