mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-28 01:26:16 +01:00
fix: change translator escape
remove \\\] and \\\[ match double ] and [
This commit is contained in:
@@ -463,7 +463,9 @@ module.exports = function (utils, load, warn) {
|
||||
* @returns {string}
|
||||
*/
|
||||
Translator.escape = function escape(text) {
|
||||
return typeof text === 'string' ? text.replace(/\[\[/g, '[[').replace(/\]\]/g, ']]') : text;
|
||||
return typeof text === 'string' ?
|
||||
text.replace(/\[\[/g, '[[').replace(/\]\]/g, ']]') :
|
||||
text;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -473,8 +475,7 @@ module.exports = function (utils, load, warn) {
|
||||
*/
|
||||
Translator.unescape = function unescape(text) {
|
||||
return typeof text === 'string' ?
|
||||
text.replace(/[/g, '[').replace(/\\\[/g, '[')
|
||||
.replace(/]/g, ']').replace(/\\\]/g, ']') :
|
||||
text.replace(/]]/g, ']]').replace(/[[/g, '[[') :
|
||||
text;
|
||||
};
|
||||
|
||||
|
||||
@@ -308,10 +308,6 @@ describe('Translator static methods', () => {
|
||||
|
||||
describe('.unescape', () => {
|
||||
it('should unescape escaped translation patterns within text', (done) => {
|
||||
assert.strictEqual(
|
||||
Translator.unescape('some nice text \\[\\[global:home\\]\\] here'),
|
||||
'some nice text [[global:home]] here'
|
||||
);
|
||||
assert.strictEqual(
|
||||
Translator.unescape('some nice text [[global:home]] here'),
|
||||
'some nice text [[global:home]] here'
|
||||
|
||||
Reference in New Issue
Block a user