Escape arguments in `Translator.compile`

v1.18.x
Peter Jaszkowiak 8 years ago
parent a81aad61ab
commit bb5fe0cc83

@ -399,9 +399,12 @@
* @param {...string} arg - Optional argument for the pattern * @param {...string} arg - Optional argument for the pattern
*/ */
Translator.compile = function compile() { 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; return Translator;

@ -251,5 +251,13 @@ describe('Translator static methods', function () {
); );
done(); 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();
});
}); });
}); });

Loading…
Cancel
Save