Skip to content

Node.js based forum software built for the modern web

fix: make translator.unescape stricter like escape

Barış Soner Uşaklıe505e3699121
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', () => {