fix: change translator escape

remove \\\] and \\\[
match double ] and [
This commit is contained in:
Barış Soner Uşaklı
2023-12-08 10:58:13 -05:00
parent 17cd19c701
commit c434262e21
2 changed files with 4 additions and 7 deletions

View File

@@ -463,7 +463,9 @@ module.exports = function (utils, load, warn) {
* @returns {string} * @returns {string}
*/ */
Translator.escape = function escape(text) { 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) { Translator.unescape = function unescape(text) {
return typeof text === 'string' ? return typeof text === 'string' ?
text.replace(/[/g, '[').replace(/\\\[/g, '[') text.replace(/]]/g, ']]').replace(/[[/g, '[[') :
.replace(/]/g, ']').replace(/\\\]/g, ']') :
text; text;
}; };

View File

@@ -308,10 +308,6 @@ describe('Translator static methods', () => {
describe('.unescape', () => { describe('.unescape', () => {
it('should unescape escaped translation patterns within text', (done) => { 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( assert.strictEqual(
Translator.unescape('some nice text [[global:home]] here'), Translator.unescape('some nice text [[global:home]] here'),
'some nice text [[global:home]] here' 'some nice text [[global:home]] here'