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

This commit is contained in:
Joffrey JAFFEUX 2020-10-27 11:05:10 +01:00 committed by GitHub
parent 8253f8fc5c
commit 5fc239b535
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 1 deletions

View File

@ -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');
},
});

View File

@ -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
);
}
),