Node.js based forum software built for the modern web
Escape and ignore `%` and `\,` in translator args
Peter Jaszkowiak7c697759e9da
diff --git a/public/src/modules/translator.js b/public/src/modules/translator.jsindex a876dba44c..e60385ed79 100644--- a/public/src/modules/translator.js+++ b/public/src/modules/translator.js@@ -105,7 +105,7 @@} else if (text.slice(i, i + 2) === ']]') {level -= 1;i += 1;- } else if (level === 0 && text[i] === ',') {+ } else if (level === 0 && text[i] === ',' && text[i - 1] !== '\\') {arr.push(text.slice(brk, i).trim());i += 1;brk = i;@@ -260,7 +260,8 @@}var out = translated;translatedArgs.forEach(function (arg, i) {- out = out.replace(new RegExp('%' + (i + 1), 'g'), arg);+ var escaped = arg.replace(/%/g, '%').replace(/\\,/g, ',');+ out = out.replace(new RegExp('%' + (i + 1), 'g'), escaped);});return out;});diff --git a/test/translator.js b/test/translator.jsindex 91fbf8f696..f52fd7c79c 100644--- a/test/translator.js+++ b/test/translator.js@@ -127,14 +127,13 @@ describe('new Translator(language)', function () {});});- it('should properly escape % and ,', function (done) {+ it('should properly escape and ignore % and \\, in arguments', function (done) {var translator = Translator.create('en-GB');- var title = 'Test 1, 2, 3 % salmon';- title = title.replace(/%/g, '%').replace(/,/g, ',');+ var title = 'Test 1\\, 2\\, 3 % salmon';var key = "[[topic:composer.replying_to, " + title + "]]";translator.translate(key).then(function (translated) {- assert.strictEqual(translated, 'Replying to Test 1, 2, 3 % salmon');+ assert.strictEqual(translated, 'Replying to Test 1, 2, 3 % salmon');done();});});