diff --git a/packages/@ember/-internals/glimmer/tests/utils/string-test.js b/packages/@ember/-internals/glimmer/tests/utils/string-test.js index 139c6c3846d..feca7406a85 100644 --- a/packages/@ember/-internals/glimmer/tests/utils/string-test.js +++ b/packages/@ember/-internals/glimmer/tests/utils/string-test.js @@ -11,6 +11,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 bold'.htmlSafe(); + }, /String prototype extensions are deprecated./); + + this.assert.ok(safeString instanceof SafeString, 'should be a SafeString'); + } else { + assert.expect(0); + } + } + ['@test htmlSafe should return an empty string for null']() { let safeString = htmlSafe(null); @@ -24,6 +37,30 @@ 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 { + 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 { + assert.expect(0); + } + } } ); diff --git a/packages/ember/index.js b/packages/ember/index.js index 7709b6b9448..e1162eccb52 100644 --- a/packages/ember/index.js +++ b/packages/ember/index.js @@ -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.`, + 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); }; }