mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-02-14 02:27:49 +01:00
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:
@@ -464,7 +464,7 @@ module.exports = function (utils, load, warn) {
|
||||
*/
|
||||
Translator.escape = function escape(text) {
|
||||
return typeof text === 'string' ?
|
||||
text.replace(/\[\[/g, '[[').replace(/\]\]/g, ']]') :
|
||||
text.replace(/\[\[([a-zA-Z0-9_.-]+:[a-zA-Z0-9_.-]+)\]\]/g, '[[$1]]') :
|
||||
text;
|
||||
};
|
||||
|
||||
|
||||
@@ -334,6 +334,22 @@ describe('Translator static methods', () => {
|
||||
);
|
||||
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', () => {
|
||||
|
||||
Reference in New Issue
Block a user