mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
fix: #9206, fix double escaped arguments
This commit is contained in:
@@ -286,6 +286,9 @@
|
||||
var out = translated;
|
||||
translatedArgs.forEach(function (arg, i) {
|
||||
var escaped = arg.replace(/%(?=\d)/g, '%').replace(/\\,/g, ',');
|
||||
// fix double escaped translation keys, see https://github.com/NodeBB/NodeBB/issues/9206
|
||||
escaped = escaped.replace(/[/g, '[')
|
||||
.replace(/]/g, ']');
|
||||
out = out.replace(new RegExp('%' + (i + 1), 'g'), escaped);
|
||||
});
|
||||
return out;
|
||||
|
||||
@@ -135,6 +135,16 @@ describe('new Translator(language)', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should translate escaped translation arguments properly', function () {
|
||||
// https://github.com/NodeBB/NodeBB/issues/9206
|
||||
var translator = Translator.create('en-GB');
|
||||
|
||||
var key = '[[notifications:upvoted_your_post_in, test1, error: Error: [[error:group-name-too-long]] on NodeBB Upgrade]]';
|
||||
return translator.translate(key).then(function (translated) {
|
||||
assert.strictEqual(translated, '<strong>test1</strong> has upvoted your post in <strong>error: Error: [[error:group-name-too-long]] on NodeBB Upgrade</strong>.');
|
||||
});
|
||||
});
|
||||
|
||||
it('should properly escape and ignore % and \\, in arguments', function () {
|
||||
var translator = Translator.create('en-GB');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user