Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX release] Deprecate htmlSafe via prototype #19690

Merged
merged 1 commit into from
Aug 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 40 additions & 0 deletions packages/@ember/-internals/glimmer/tests/utils/string-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
import { ENV } from '@ember/-internals/environment';

import { SafeString, htmlSafe, isHTMLSafe } from './helpers';

Expand All @@ -11,6 +12,19 @@ moduleFor(
this.assert.ok(safeString instanceof SafeString, 'should be a SafeString');
}

['@test [deprecated] htmlSafe via string prototype should return an instance of SafeString']() {
if (ENV.EXTEND_PROTOTYPES.String) {
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');
} else {
this.assert.expect(0);
}
}

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

Expand All @@ -24,6 +38,32 @@ 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']() {
if (ENV.EXTEND_PROTOTYPES.String) {
let safeString;
expectDeprecation(() => {
safeString = ''.htmlSafe();
}, /String prototype extensions are deprecated/);

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

['@test [deprecated] String.prototype.htmlSafe is not modified without EXTEND_PROTOTYPES'](
assert
) {
if (!ENV.EXTEND_PROTOTYPES.String) {
assert.ok(
'undefined' === typeof String.prototype.htmlSafe,
'String.prototype helper disabled'
);
} else {
this.assert.expect(0);
}
}
}
);

Expand Down
13 changes: 13 additions & 0 deletions packages/ember/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,19 @@ 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.`,
false,
{
id: 'ember-string.prototype-extensions',
for: 'ember-source',
since: {
enabled: '3.27.6',
Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be the next 3.27 release.

},
until: '4.0.0',
url: 'https://deprecations.emberjs.com/v3.x/#toc_ember-string-htmlsafe-ishtmlsafe',
}
);
return htmlSafe(this);
};
}
Expand Down