Skip to content

A platform for community discussion. Free, open, simple.

FIX: converts html to text to use it as title attribute (#11009)

Joffrey JAFFEUX5fc239b535ec
diff --git a/app/assets/javascripts/discourse/tests/integration/components/select-kit/category-chooser-test.js b/app/assets/javascripts/discourse/tests/integration/components/select-kit/category-chooser-test.js
index 5ccdf32e38e..7f722fb5a6e 100644
--- a/app/assets/javascripts/discourse/tests/integration/components/select-kit/category-chooser-test.js
+++ b/app/assets/javascripts/discourse/tests/integration/components/select-kit/category-chooser-test.js
@@ -194,3 +194,29 @@ componentTest("filter works with non english characters", {
assert.equal(this.subject.rowByIndex(0).name(), "chữ Quốc ngữ");
},
});
+
+componentTest("decodes entities in row title", {
+ template: `
+ {{category-chooser
+ value=value
+ content=content
+ }}
+ `,
+
+ beforeEach() {
+ const store = createStore();
+ const catWithEntities = store.createRecord("category", {
+ id: 1,
+ name: "cat-with-entities",
+ description: "baz "bar ‘foo’",
+ });
+
+ this.set("content", [catWithEntities]);
+ },
+
+ async test(assert) {
+ await this.subject.expand();
+
+ assert.equal(this.subject.rowByIndex(0).el()[0].title, 'baz "bar ‘foo’');
+ },
+});
diff --git a/app/assets/javascripts/select-kit/addon/components/category-row.js b/app/assets/javascripts/select-kit/addon/components/category-row.js
index daa5bd2087a..6026f455533 100644
--- a/app/assets/javascripts/select-kit/addon/components/category-row.js
+++ b/app/assets/javascripts/select-kit/addon/components/category-row.js
@@ -7,6 +7,12 @@ import { computed } from "@ember/object";
import { setting } from "discourse/lib/computed";
import layout from "select-kit/templates/components/category-row";
+function htmlToText(encodedString) {
+ const elem = document.createElement("textarea");
+ elem.innerHTML = encodedString;
+ return elem.value;
+}
+
export default SelectKitRowComponent.extend({
layout,
classNames: ["category-row"],
@@ -33,7 +39,9 @@ export default SelectKitRowComponent.extend({
"description",
"categoryName",
function () {
- return this.descriptionText || this.description || this.categoryName;
+ return htmlToText(
+ this.descriptionText || this.description || this.categoryName
+ );
}
),