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

@ -155,7 +155,7 @@
while (cursor + 2 <= len) {
sliced = str.slice(cursor, cursor + 2);
// found some text after the double bracket,
// found some text after the double bracket,
// so this is probably a translation string
if (!textBeforeColonFound && validTextRegex.test(sliced[0])) {
textBeforeColonFound = true;
@ -174,7 +174,7 @@
cursor += 1;
// a space or comma was found before the name
// this isn't a translation string, so back out
} else if (!(textBeforeColonFound && colonFound && textAfterColonFound && commaAfterNameFound) &&
} else if (!(textBeforeColonFound && colonFound && textAfterColonFound && commaAfterNameFound) &&
invalidTextRegex.test(sliced[0])) {
cursor += 1;
lastBreak -= 2;
@ -272,7 +272,7 @@
}
var out = translated;
translatedArgs.forEach(function (arg, i) {
var escaped = arg.replace(/%/g, '&#37;').replace(/\\,/g, '&#44;');
var escaped = arg.replace(/%(?=\d)/g, '&#37;').replace(/\\,/g, '&#44;');
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&#44; 2&#44; 3 &#37; salmon');
assert.strictEqual(translated, 'Replying to Test 1&#44; 2&#44; 3 &#37;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');
});
});
@ -173,7 +184,7 @@ describe('Translator.create()', function () {
describe('Translator modules', function () {
it('should work before registered', function () {
var translator = Translator.create();
Translator.registerModule('test-custom-integer-format', function (lang) {
return function (key, args) {
var num = parseInt(args[0], 10) || 0;

Loading…
Cancel
Save