diff --git a/packages/ember-htmlbars/lib/utils/string.js b/packages/ember-htmlbars/lib/utils/string.js index 4ebab084f03..3a164912e41 100644 --- a/packages/ember-htmlbars/lib/utils/string.js +++ b/packages/ember-htmlbars/lib/utils/string.js @@ -24,10 +24,8 @@ import { SafeString, escapeExpression } from 'htmlbars-util'; */ function htmlSafe(str) { if (str === null || str === undefined) { - return ''; - } - - if (typeof str !== 'string') { + str = ''; + } else if (typeof str !== 'string') { str = '' + str; } return new SafeString(str); diff --git a/packages/ember-htmlbars/tests/utils/string_test.js b/packages/ember-htmlbars/tests/utils/string_test.js index 8a57ad1661e..f9a9287e650 100644 --- a/packages/ember-htmlbars/tests/utils/string_test.js +++ b/packages/ember-htmlbars/tests/utils/string_test.js @@ -6,13 +6,19 @@ QUnit.module('ember-htmlbars: SafeString'); QUnit.test('htmlSafe should return an instance of SafeString', function() { var safeString = htmlSafe('you need to be more bold'); - ok(safeString instanceof SafeString, 'should return SafeString'); + ok(safeString instanceof SafeString, 'should be a SafeString'); }); QUnit.test('htmlSafe should return an empty string for null', function() { - equal(htmlSafe(null).toString(), '', 'should return an empty string'); + var safeString = htmlSafe(null); + + equal(safeString instanceof SafeString, true, 'should be a SafeString'); + equal(safeString.toString(), '', 'should return an empty string'); }); QUnit.test('htmlSafe should return an empty string for undefined', function() { - equal(htmlSafe().toString(), '', 'should return an empty string'); + var safeString = htmlSafe(); + + equal(safeString instanceof SafeString, true, 'should be a SafeString'); + equal(safeString.toString(), '', 'should return an empty string'); });