From bb5fe0cc8396bcecd2bb519a148d365ebc6f3a40 Mon Sep 17 00:00:00 2001 From: Peter Jaszkowiak Date: Sat, 10 Dec 2016 20:41:49 -0700 Subject: [PATCH] Escape arguments in `Translator.compile` --- public/src/modules/translator.js | 7 +++++-- test/translator.js | 8 ++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/public/src/modules/translator.js b/public/src/modules/translator.js index d975e16e1d..30b67ef3a8 100644 --- a/public/src/modules/translator.js +++ b/public/src/modules/translator.js @@ -399,9 +399,12 @@ * @param {...string} arg - Optional argument for the pattern */ Translator.compile = function compile() { - var args = Array.prototype.slice.call(arguments, 0); + var args = Array.prototype.slice.call(arguments, 0).map(function (text) { + // escape commas and percent signs in arguments + return text.replace(/%/g, '%').replace(/,/g, ','); + }); - return '[[' + args.join(', ') + ']]'; + return '[[' + args.join(', ') + ']]'; }; return Translator; diff --git a/test/translator.js b/test/translator.js index a89681adef..8198814164 100644 --- a/test/translator.js +++ b/test/translator.js @@ -251,5 +251,13 @@ describe('Translator static methods', function () { ); done(); }); + + it('should escape `%` and `,` in arguments', function (done) { + assert.strictEqual( + Translator.compile('amazing:cool', '100% awesome!', 'one, two, and three'), + '[[amazing:cool, 100% awesome!, one, two, and three]]' + ); + done(); + }); }); });