FIX: correctly display escaped thread titles (#24159)

Prior to this fix, titles with a quote `'` for example, would be rendered as: `&#x27`
This commit is contained in:
Joffrey JAFFEUX 2023-10-30 21:06:31 +01:00 committed by GitHub
parent 56e233464f
commit 4859340b2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 52 additions and 16 deletions

View File

@ -15,8 +15,8 @@
> >
<div class="chat-thread-list-item__header"> <div class="chat-thread-list-item__header">
<div class="chat-thread-list-item__title"> <div class="chat-thread-list-item__title">
{{#if this.title}} {{#if @thread.title}}
{{replace-emoji this.title}} {{replace-emoji @thread.title}}
{{else}} {{else}}
{{replace-emoji @thread.originalMessage.excerpt}} {{replace-emoji @thread.originalMessage.excerpt}}
{{/if}} {{/if}}

View File

@ -5,10 +5,6 @@ import { inject as service } from "@ember/service";
export default class ChatThreadListItem extends Component { export default class ChatThreadListItem extends Component {
@service router; @service router;
get title() {
return this.args.thread.escapedTitle;
}
@action @action
openThread(thread) { openThread(thread) {
this.router.transitionTo("chat.channel.thread", ...thread.routeModels); this.router.transitionTo("chat.channel.thread", ...thread.routeModels);

View File

@ -14,7 +14,7 @@
</div> </div>
<span class="chat-thread-header__label overflow-ellipsis"> <span class="chat-thread-header__label overflow-ellipsis">
{{replace-emoji this.label}} {{replace-emoji @thread.title}}
</span> </span>
<div <div

View File

@ -36,10 +36,6 @@ export default class ChatThreadHeader extends Component {
}; };
} }
get label() {
return this.args.thread.escapedTitle;
}
get canChangeThreadSettings() { get canChangeThreadSettings() {
if (!this.args.thread) { if (!this.args.thread) {
return false; return false;

View File

@ -127,6 +127,7 @@ function threadFabricator(args = {}) {
const channel = args.channel || channelFabricator(); const channel = args.channel || channelFabricator();
return ChatThread.create(channel, { return ChatThread.create(channel, {
id: args.id || sequence++, id: args.id || sequence++,
title: args.title,
original_message: args.original_message || messageFabricator({ channel }), original_message: args.original_message || messageFabricator({ channel }),
preview: args.preview || threadPreviewFabricator({ channel }), preview: args.preview || threadPreviewFabricator({ channel }),
}); });

View File

@ -1,6 +1,5 @@
import { tracked } from "@glimmer/tracking"; import { tracked } from "@glimmer/tracking";
import guid from "pretty-text/guid"; import guid from "pretty-text/guid";
import { escapeExpression } from "discourse/lib/utilities";
import { getOwnerWithFallback } from "discourse-common/lib/get-owner"; import { getOwnerWithFallback } from "discourse-common/lib/get-owner";
import ChatMessagesManager from "discourse/plugins/chat/discourse/lib/chat-messages-manager"; import ChatMessagesManager from "discourse/plugins/chat/discourse/lib/chat-messages-manager";
import ChatMessage from "discourse/plugins/chat/discourse/models/chat-message"; import ChatMessage from "discourse/plugins/chat/discourse/models/chat-message";
@ -73,8 +72,4 @@ export default class ChatThread {
get routeModels() { get routeModels() {
return [...this.channel.routeModels, this.id]; return [...this.channel.routeModels, this.id];
} }
get escapedTitle() {
return escapeExpression(this.title);
}
} }

View File

@ -0,0 +1,24 @@
import { render } from "@ember/test-helpers";
import hbs from "htmlbars-inline-precompile";
import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { query } from "discourse/tests/helpers/qunit-helpers";
import fabricators from "discourse/plugins/chat/discourse/lib/fabricators";
module("Discourse Chat | Component | chat-thread-header", function (hooks) {
setupRenderingTest(hooks);
test("it safely renders title", async function (assert) {
const title = "<style>body { background: red;}</style>";
this.thread = fabricators.thread({ title });
await render(hbs`
<Chat::Thread::Header @thread={{this.thread}} @channel={{this.thread.channel}} />
`);
assert.equal(
query(".chat-thread-header__label").innerHTML.trim(),
"&lt;style&gt;body { background: red;}&lt;/style&gt;"
);
});
});

View File

@ -0,0 +1,24 @@
import { render } from "@ember/test-helpers";
import hbs from "htmlbars-inline-precompile";
import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { query } from "discourse/tests/helpers/qunit-helpers";
import fabricators from "discourse/plugins/chat/discourse/lib/fabricators";
module("Discourse Chat | Component | chat-thread-list-item", function (hooks) {
setupRenderingTest(hooks);
test("it safely renders title", async function (assert) {
const title = "<style>body { background: red;}</style>";
this.thread = fabricators.thread({ title });
await render(hbs`
<Chat::ThreadList::Item @thread={{this.thread}} />
`);
assert.equal(
query(".chat-thread-list-item__title").innerHTML.trim(),
"&lt;style&gt;body { background: red;}&lt;/style&gt;"
);
});
});