Skip to content

Node.js based forum software built for the modern web

updated translator so that language key parameters cannot contain html in them (or more specifically, < and >)

Julian Lam99315e1c737c
diff --git a/public/language/en_GB/global.json b/public/language/en_GB/global.json
index 0a79ed2c1e..07b6b40a60 100644
--- a/public/language/en_GB/global.json
+++ b/public/language/en_GB/global.json
@@ -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",
diff --git a/public/src/modules/translator.js b/public/src/modules/translator.js
index a6258100d6..0824cce59e 100644
--- a/public/src/modules/translator.js
+++ b/public/src/modules/translator.js
@@ -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: /\]+$/
};
diff --git a/tests/translator.js b/tests/translator.js
index 67a6441040..c3f01b4d15 100644
--- a/tests/translator.js
+++ b/tests/translator.js
@@ -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();
+ });
+ })
});
});