v1.18.x
barisusakli 8 years ago
parent 7414482753
commit f1f00b63fb

@ -272,7 +272,7 @@
}
var out = translated;
translatedArgs.forEach(function (arg, i) {
var escaped = arg.replace(/%/g, '%').replace(/\\,/g, ',');
var escaped = arg.replace(/%(?=\d)/g, '%').replace(/\\,/g, ',');
out = out.replace(new RegExp('%' + (i + 1), 'g'), escaped);
});
return out;

@ -4,6 +4,7 @@
var assert = require('assert');
var shim = require('../public/src/modules/translator.js');
var Translator = shim.Translator;
var db = require('./mocks/databasemock');
require('../src/languages').init(function () {});
@ -118,10 +119,20 @@ describe('new Translator(language)', function () {
it('should properly escape and ignore % and \\, in arguments', function () {
var translator = Translator.create('en-GB');
var title = 'Test 1\\, 2\\, 3 % salmon';
var title = 'Test 1\\, 2\\, 3 %2 salmon';
var key = "[[topic:composer.replying_to, " + title + "]]";
return 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 %2 salmon');
});
});
it('should not escape regular %', function () {
var translator = Translator.create('en-GB');
var title = '3 % salmon';
var key = "[[topic:composer.replying_to, " + title + "]]";
return translator.translate(key).then(function (translated) {
assert.strictEqual(translated, 'Replying to 3 % salmon');
});
});

Loading…
Cancel
Save