mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-02-14 02:27:49 +01:00
fix: make translator.unescape stricter like escape
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
Reference in New Issue
Block a user