diff --git a/src/mibew/js/source/default/handlebars_helpers.js b/src/mibew/js/source/default/handlebars_helpers.js index 68e6a1d4..0311dd8c 100644 --- a/src/mibew/js/source/default/handlebars_helpers.js +++ b/src/mibew/js/source/default/handlebars_helpers.js @@ -96,7 +96,7 @@ */ Handlebars.registerHelper('urlReplace', function(text) { return new Handlebars.SafeString( - text.replace( + text.toString().replace( /((?:https?|ftp):\/\/\S*)/g, '$1' ) 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 1c641188..5255a189 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 @@ -72,6 +72,42 @@ test('apply', function() { } }); +// Test "urlReplace" Handlebars helper +test('urlReplace', function() { + var template = '{{urlReplace foo}}'; + var compiledTemplate = Handlebars.compile(template); + + equal( + compiledTemplate({foo: 'http://example.com'}), + 'http://example.com', + 'Test HTTP URL' + ); + + equal( + compiledTemplate({foo: 'https://example.com'}), + 'https://example.com', + 'Test HTTPS URL' + ); + + equal( + compiledTemplate({foo: 'ftp://example.com'}), + 'ftp://example.com', + 'Test FTP URL' + ); + + equal( + compiledTemplate({foo: 'plain text'}), + 'plain text', + 'Test not a URL' + ); + + equal( + compiledTemplate({foo: 456}), + '456', + 'Test number argument' + ); +}); + // Test "nl2br" Handlebars helper test('nl2br', function() { var template = '{{nl2br foo}}';