fix: make translator.unescape stricter like escape

This commit is contained in:
Barış Soner Uşaklı
2026-01-16 13:17:02 -05:00
parent b2fa7304e9
commit e505e36991
2 changed files with 10 additions and 4 deletions

View File

@@ -475,7 +475,7 @@ module.exports = function (utils, load, warn) {
*/ */
Translator.unescape = function unescape(text) { Translator.unescape = function unescape(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

@@ -326,7 +326,7 @@ describe('Translator static methods', () => {
done(); done();
}); });
}); });
describe('.escape', () => { describe('.escape/.unescape', () => {
it('should escape translation patterns within text', (done) => { it('should escape translation patterns within text', (done) => {
assert.strictEqual( assert.strictEqual(
Translator.escape('some nice text [[global:home]] here'), Translator.escape('some nice text [[global:home]] here'),
@@ -350,9 +350,7 @@ describe('Translator static methods', () => {
); );
done(); done();
}); });
});
describe('.unescape', () => {
it('should unescape escaped translation patterns within text', (done) => { it('should unescape escaped translation patterns within text', (done) => {
assert.strictEqual( assert.strictEqual(
Translator.unescape('some nice text [[global:home]] here'), Translator.unescape('some nice text [[global:home]] here'),
@@ -360,6 +358,14 @@ describe('Translator static methods', () => {
); );
done(); 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', () => { describe('.compile', () => {