mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-06 15:42:52 +01:00
Escape and ignore % and \, in translator args
This commit is contained in:
@@ -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;
|
||||
});
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user