Skip to content

Commit

Permalink
[BUGFIX release] Deprecate htmlSafe via prototype
Browse files Browse the repository at this point in the history
In Ember 3.24 various string methods added to the `String.prototype` were
deprecated for removal in Ember 4.0. `htmlSafe` (the version available
via string prototype) was supposed to be included in those deprecations,
however dues to its implementation being different it was missed. This
ommission can be understood as a bug.

This patch deprecates `String.prototype.htmlSafe` targeting Ember 4.0.
This will allow the removal of *all* string prototype extensions in 4.0
as intended by the original deprecation.
  • Loading branch information
mixonic committed Aug 1, 2021
1 parent 2b209f8 commit 8738d5d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/@ember/-internals/glimmer/tests/utils/string-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ moduleFor(
this.assert.ok(safeString instanceof SafeString, 'should be a SafeString');
}

['@test [deprecated] htmlSafe via string prototype should return an instance of SafeString']() {
let safeString;
expectDeprecation(() => {
safeString = 'you need to be more <b>bold</b>'.htmlSafe();
}, /String prototype extensions are deprecated./);

this.assert.ok(safeString instanceof SafeString, 'should be a SafeString');
}

['@test htmlSafe should return an empty string for null']() {
let safeString = htmlSafe(null);

Expand All @@ -24,6 +33,15 @@ moduleFor(
this.assert.equal(safeString instanceof SafeString, true, 'should be a SafeString');
this.assert.equal(safeString.toString(), '', 'should return an empty string');
}

['@test [deprecated] htmlSafe via string prototype should return an instance of SafeString for an empty string']() {
let safeString;
expectDeprecation(() => {
safeString = ''.htmlSafe();
}, /String prototype extensions are deprecated./);

this.assert.ok(safeString instanceof SafeString, 'should be a SafeString');
}
}
);

Expand Down
9 changes: 9 additions & 0 deletions packages/ember/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,15 @@ Ember._captureRenderTree = captureRenderTree;

if (ENV.EXTEND_PROTOTYPES.String) {
String.prototype.htmlSafe = function () {
deprecate(`String prototype extensions are deprecated. Please import htmlSafe from '@ember/template' instead.`, true, {
id: 'ember-string.prototype-extensions',
for: 'ember-source',
since: {
enabled: '3.27.1',
},
until: '4.0.0',
url: 'https://deprecations.emberjs.com/v3.x/#toc_ember-string-htmlsafe-ishtmlsafe',
});
return htmlSafe(this);
};
}
Expand Down

0 comments on commit 8738d5d

Please sign in to comment.