Node.js based forum software built for the modern web
reverted latest change to translator match regex
Julian Lambaaad1328696
diff --git a/public/src/modules/translator.js b/public/src/modules/translator.jsindex 0824cce59e..6c3db46116 100644--- a/public/src/modules/translator.js+++ b/public/src/modules/translator.js@@ -2,14 +2,21 @@"use strict";/* globals RELATIVE_PATH, config, define */+ var S;+// export the class if we are in a Node-like system.if (typeof module === 'object' && module.exports === translator) {exports = module.exports = translator;+ S = require('string');+ } else {+ require(['string'], function(stringLib) {+ S = stringLib;+ });}var languages = {},regexes = {- match: /\[\[\w+:[\w\.]+((?!\[\[|<|>|\(|\)).)*?\]\]/g, // see tests/translator.js for an explanation re: this monster+ match: /\[\[\w+:[\w\.]+((?!\[\[).)*?\]\]/g, // see tests/translator.js for an explanation re: this monstersplit: /[,][\s]*/,replace: /\]+$/};@@ -187,8 +194,9 @@function insertLanguage(text, key, value, variables) {if (value) {+ var variable;for (var i = 1, ii = variables.length; i < ii; i++) {- var variable = variables[i].replace(']]', '');+ variable = S(variables[i]).chompRight(']]').collapseWhitespace().escapeHTML().s;value = value.replace('%' + i, variable);}diff --git a/src/meta/templates.js b/src/meta/templates.jsindex cc6f6ad2cd..9a5aa5c72b 100644--- a/src/meta/templates.js+++ b/src/meta/templates.js@@ -76,7 +76,6 @@ Templates.compile = function(callback) {baseTpls.forEach(function(el, i) {paths[baseTpls[i]] = path.join(baseTemplatesPath, baseTpls[i]);});-// console.log(pluginTemplates);for (var tpl in pluginTemplates) {if (pluginTemplates.hasOwnProperty(tpl)) {diff --git a/tests/translator.js b/tests/translator.jsindex c3f01b4d15..ede6acd75a 100644--- a/tests/translator.js+++ b/tests/translator.js@@ -71,10 +71,17 @@ describe('Translator', function(){});});+ it('should properly handle parameters that contain parentheses', function(done) {+ translator.translate('[[global:pagination.out_of, (foobar), [[global:home]]]]', function(translated) {+ assert.strictEqual(translated, '(foobar) 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);+ assert.strictEqual(translated, 'Perhaps you should <a href=\'<strong>test</strong>/login\'>try logging in</a>?');done();});})