From 0b9fdeceb81ae03de3615f7bb719f61cf5a4fe00 Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Thu, 11 Sep 2014 12:15:19 +0000 Subject: [PATCH] Fix number arguments in "allowTags" Handlebars.js helper --- .../js/source/default/handlebars_helpers.js | 2 +- .../test_cases/handlebars_helpers_tests.js | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) 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}}';