Skip to content

Commit

Permalink
[BUGFIX release] Ember.String.htmlSafe() should return a instance o…
Browse files Browse the repository at this point in the history
…f SafeString for `null` / `undefined`

Currently, `Ember.String.htmlSafe()` returns a just String, not HTML Safe.
We expect it is a safe string.
  • Loading branch information
tricknotes committed Oct 9, 2015
1 parent e15e5d5 commit cddb12b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
6 changes: 2 additions & 4 deletions packages/ember-htmlbars/lib/utils/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 9 additions & 3 deletions packages/ember-htmlbars/tests/utils/string_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <b>bold</b>');

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');
});

0 comments on commit cddb12b

Please sign in to comment.