DEV: Future-proof htmlSafe interactions (#23596)

See https://github.com/discourse/discourse-encrypt/pull/282

> `cooked` was an Ember SafeString. The internal storage of the string changed from `.string` to `.__string` at some point between Ember 3.28 and Ember 5. Instead, we can use `toString()` which is guaranteed to work in all situations
This commit is contained in:
Jarek Radosz 2023-09-14 23:04:57 +02:00 committed by GitHub
parent ed8d0656f9
commit c75b379d6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 13 additions and 11 deletions

View File

@ -47,7 +47,7 @@ export default Controller.extend(ModalFunctionality, {
? { ? {
type: "custom", type: "custom",
raw: notice, raw: notice,
cooked: cooked.string, cooked: cooked.toString(),
} }
: null : null
) )

View File

@ -69,7 +69,7 @@ export default RestModel.extend({
const promises = result.drafts.map((draft) => { const promises = result.drafts.map((draft) => {
draft.data = JSON.parse(draft.data); draft.data = JSON.parse(draft.data);
return cookAsync(draft.data.reply).then((cooked) => { return cookAsync(draft.data.reply).then((cooked) => {
draft.excerpt = excerpt(cooked.string, 300); draft.excerpt = excerpt(cooked.toString(), 300);
draft.post_number = draft.data.postId || null; draft.post_number = draft.data.postId || null;
if ( if (
draft.draft_key === NEW_PRIVATE_MESSAGE_KEY || draft.draft_key === NEW_PRIVATE_MESSAGE_KEY ||

View File

@ -172,6 +172,6 @@ module("Unit | Utility | computed", function (hooks) {
desc: htmlSafe("cookies"), desc: htmlSafe("cookies"),
}).create({ cookies }); }).create({ cookies });
assert.strictEqual(t.desc.string, cookies); assert.strictEqual(t.desc.toString(), cookies);
}); });
}); });

View File

@ -58,8 +58,8 @@ module("Unit | lib | Experimental lightbox | processHTML()", function () {
assert.strictEqual(item.index, LIGHTBOX_IMAGE_FIXTURES.first.index); assert.strictEqual(item.index, LIGHTBOX_IMAGE_FIXTURES.first.index);
assert.strictEqual( assert.strictEqual(
item.cssVars.string, item.cssVars.toString(),
LIGHTBOX_IMAGE_FIXTURES.first.cssVars.string LIGHTBOX_IMAGE_FIXTURES.first.cssVars.toString()
); );
assert.strictEqual(startingIndex, 0); assert.strictEqual(startingIndex, 0);
@ -140,7 +140,7 @@ module("Unit | lib | Experimental lightbox | processHTML()", function () {
assert.strictEqual(items[0].aspectRatio, null); assert.strictEqual(items[0].aspectRatio, null);
assert.strictEqual( assert.strictEqual(
items[0].cssVars.string, items[0].cssVars.toString(),
`--dominant-color: #${LIGHTBOX_IMAGE_FIXTURES.first.dominantColor};--small-url: url(${LIGHTBOX_IMAGE_FIXTURES.first.smallURL});` `--dominant-color: #${LIGHTBOX_IMAGE_FIXTURES.first.dominantColor};--small-url: url(${LIGHTBOX_IMAGE_FIXTURES.first.smallURL});`
); );
}); });
@ -171,7 +171,7 @@ module("Unit | lib | Experimental lightbox | processHTML()", function () {
assert.strictEqual(items[0].dominantColor, null); assert.strictEqual(items[0].dominantColor, null);
assert.strictEqual( assert.strictEqual(
items[0].cssVars.string, items[0].cssVars.toString(),
`--aspect-ratio: ${LIGHTBOX_IMAGE_FIXTURES.first.aspectRatio};--small-url: url(${LIGHTBOX_IMAGE_FIXTURES.first.smallURL});` `--aspect-ratio: ${LIGHTBOX_IMAGE_FIXTURES.first.aspectRatio};--small-url: url(${LIGHTBOX_IMAGE_FIXTURES.first.smallURL});`
); );
}); });
@ -250,7 +250,7 @@ module("Unit | lib | Experimental lightbox | processHTML()", function () {
); );
assert.strictEqual( assert.strictEqual(
item.cssVars.string, item.cssVars.toString(),
`--small-url: url(${LIGHTBOX_IMAGE_FIXTURES.first.fullsizeURL});` `--small-url: url(${LIGHTBOX_IMAGE_FIXTURES.first.fullsizeURL});`
); );
}); });

View File

@ -47,7 +47,7 @@ module("Unit | Model | pending-post", function (hooks) {
await settled(); await settled();
assert.strictEqual( assert.strictEqual(
post.expandedExcerpt.string, post.expandedExcerpt.toString(),
"<p><strong>bold text</strong></p>" "<p><strong>bold text</strong></p>"
); );
}); });

View File

@ -16,7 +16,7 @@ async function prepare(raw) {
const model = Post.create({ id: 42, can_edit: true }); const model = Post.create({ id: 42, can_edit: true });
const decoratorHelper = { widget, getModel: () => model }; const decoratorHelper = { widget, getModel: () => model };
const $elem = $(`<div>${cooked.string}</div>`); const $elem = $(`<div>${cooked.toString()}</div>`);
checklistSyntax($elem[0], decoratorHelper); checklistSyntax($elem[0], decoratorHelper);
currentRaw = raw; currentRaw = raw;

View File

@ -6,6 +6,8 @@ export default Component.extend({
this._super(...arguments); this._super(...arguments);
const contents = $(this.element).html(); const contents = $(this.element).html();
cookAsync(contents).then((cooked) => $(this.element).html(cooked.string)); cookAsync(contents).then((cooked) =>
$(this.element).html(cooked.toString())
);
}, },
}); });