Skip to content

Commit

Permalink
Merge pull request #12464 from tricknotes/html-safe
Browse files Browse the repository at this point in the history
[BUGFIX release] `Ember.String.htmlSafe()` should return a instance of SafeString for `null` / `undefined`
  • Loading branch information
rwjblue committed Oct 9, 2015
2 parents e75d097 + cddb12b commit 2816388
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 2816388

Please sign in to comment.