updated translator so that language key parameters cannot contain

html in them (or more specifically, < and >)
v1.18.x
Julian Lam 9 years ago
parent afbbb33878
commit 99315e1c73

@ -84,7 +84,7 @@
"replied_ago": "replied %1",
"user_posted_ago": "%1 posted %2",
"guest_posted_ago": "Guest posted %1",
"last_edited_by_ago": "last edited by %1 %2",
"last_edited_by": "last edited by %1",
"norecentposts": "No Recent Posts",
"norecenttopics": "No Recent Topics",

@ -9,7 +9,7 @@
var languages = {},
regexes = {
match: /\[\[\w+:((?!\[\[).)*?\]\]/g,
match: /\[\[\w+:[\w\.]+((?!\[\[|<|>|\(|\)).)*?\]\]/g, // see tests/translator.js for an explanation re: this monster
split: /[,][\s]*/,
replace: /\]+$/
};

@ -57,11 +57,26 @@ describe('Translator', function(){
});
});
it('should handle language keys inside language keys with all parameters as language keys', function(done) {
translator.translate('[[notifications:user_posted_to, [[global:guest]], [[global:guest]]]]', function(translated) {
assert.strictEqual(translated, '<strong>Guest</strong> has posted a reply to: <strong>Guest</strong>');
done();
});
});
it('should properly handle parameters that contain square brackets', function(done) {
translator.translate('[[global:pagination.out_of, [guest], [[global:home]]]]', function(translated) {
assert.strictEqual(translated, '[guest] out of Home');
done();
});
});
it('should not translate language key parameters with HTML in them', function(done) {
var key = '[[global:403.login, <strong>test</strong>]]';
translator.translate(key, function(translated) {
assert.strictEqual(translated, key);
done();
});
})
});
});

Loading…
Cancel
Save