mirror of
https://github.com/Mibew/mibew.git
synced 2025-03-03 18:38:31 +03:00
Fix number arguments in "allowTags" Handlebars.js helper
This commit is contained in:
parent
34017d54db
commit
0b9fdeceb8
@ -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</$1>'
|
||||
|
@ -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('<span>The content</span>')}),
|
||||
'<span>The content</span>',
|
||||
'Test a tag without attributes'
|
||||
);
|
||||
|
||||
equal(
|
||||
compiledTemplate({foo: escape('<span class="red">The content</span>')}),
|
||||
'<span class="red">The content</span>',
|
||||
'Test a tag with class attribute'
|
||||
);
|
||||
|
||||
equal(
|
||||
compiledTemplate({foo: escape('<span data-foo="bar">The content</span>')}),
|
||||
escape('<span data-foo="bar">The content</span>'),
|
||||
'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}}';
|
||||
|
Loading…
Reference in New Issue
Block a user