diff --git a/src/mibew/js/source/default/handlebars_helpers.js b/src/mibew/js/source/default/handlebars_helpers.js index 0311dd8c..bbfff4d9 100644 --- a/src/mibew/js/source/default/handlebars_helpers.js +++ b/src/mibew/js/source/default/handlebars_helpers.js @@ -56,7 +56,7 @@ * This helper unescape HTML entities for allowed (span and strong) tags. */ Handlebars.registerHelper('allowTags', function(text) { - var result = text; + var result = text.toString(); result = result.replace( /<(span|strong)>(.*?)<\/\1>/g, '<$1>$2' diff --git a/src/tests/client_side/qunit/test_cases/handlebars_helpers_tests.js b/src/tests/client_side/qunit/test_cases/handlebars_helpers_tests.js index 5255a189..c8d88e35 100644 --- a/src/tests/client_side/qunit/test_cases/handlebars_helpers_tests.js +++ b/src/tests/client_side/qunit/test_cases/handlebars_helpers_tests.js @@ -108,6 +108,43 @@ test('urlReplace', function() { ); }); +// Test "allowTags" Handlebars helper +test('allowTags', function() { + var template = '{{allowTags foo}}'; + var compiledTemplate = Handlebars.compile(template); + var escape = Handlebars.Utils.escapeExpression; + + equal( + compiledTemplate({foo: escape('The content')}), + 'The content', + 'Test a tag without attributes' + ); + + equal( + compiledTemplate({foo: escape('The content')}), + 'The content', + 'Test a tag with class attribute' + ); + + equal( + compiledTemplate({foo: escape('The content')}), + escape('The content'), + 'Test a tag with arbitrary attributes' + ); + + equal( + compiledTemplate({foo: 'content'}), + 'content', + 'Test not a tag' + ); + + equal( + compiledTemplate({foo: 456}), + '456', + 'Test not a string argument' + ); +}); + // Test "nl2br" Handlebars helper test('nl2br', function() { var template = '{{nl2br foo}}';