mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-02-14 10:37:45 +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) {
|
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -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', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user