mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 18:13:39 +08:00
FIX: converts html to text to use it as title attribute (#11009)
This commit is contained in:
parent
8253f8fc5c
commit
5fc239b535
|
@ -194,3 +194,29 @@ componentTest("filter works with non english characters", {
|
||||||
assert.equal(this.subject.rowByIndex(0).name(), "chữ Quốc ngữ");
|
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’');
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
|
@ -7,6 +7,12 @@ import { computed } from "@ember/object";
|
||||||
import { setting } from "discourse/lib/computed";
|
import { setting } from "discourse/lib/computed";
|
||||||
import layout from "select-kit/templates/components/category-row";
|
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({
|
export default SelectKitRowComponent.extend({
|
||||||
layout,
|
layout,
|
||||||
classNames: ["category-row"],
|
classNames: ["category-row"],
|
||||||
|
@ -33,7 +39,9 @@ export default SelectKitRowComponent.extend({
|
||||||
"description",
|
"description",
|
||||||
"categoryName",
|
"categoryName",
|
||||||
function () {
|
function () {
|
||||||
return this.descriptionText || this.description || this.categoryName;
|
return htmlToText(
|
||||||
|
this.descriptionText || this.description || this.categoryName
|
||||||
|
);
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user