FIX: Allow safe html in poll options (#27741)

This commit is contained in:
Robert 2024-07-07 14:08:00 +01:00 committed by GitHub
parent 6022cc2af8
commit f86a95d282
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 36 additions and 3 deletions

View File

@ -3,6 +3,7 @@ import { fn } from "@ember/helper";
import { on } from "@ember/modifier";
import { action } from "@ember/object";
import { inject as service } from "@ember/service";
import { htmlSafe } from "@ember/template";
import routeAction from "discourse/helpers/route-action";
import icon from "discourse-common/helpers/d-icon";
@ -37,7 +38,7 @@ export default class PollOptionsComponent extends Component {
{{icon "far-circle"}}
{{/if}}
{{/if}}
<span class="option-text">{{option.html}}</span>
<span class="option-text">{{htmlSafe option.html}}</span>
</button>
{{else}}
<button onclick={{routeAction "showLogin"}}>
@ -54,7 +55,7 @@ export default class PollOptionsComponent extends Component {
{{icon "far-circle"}}
{{/if}}
{{/if}}
<span class="option-text">{{option.html}}</span>
<span class="option-text">{{htmlSafe option.html}}</span>
</button>
{{/if}}
</li>

View File

@ -74,7 +74,7 @@ export default class PollResultsStandardComponent extends Component {
"number.percent"
count=option.percentage
}}</span>
<span class="option-text">{{option.html}}</span>
<span class="option-text">{{htmlSafe option.html}}</span>
</p>
<div class="bar-back">
<div

View File

@ -10,6 +10,21 @@ const OPTIONS = [
{ id: "6c986ebcde3d5822a6e91a695c388094", html: "Other", votes: 0, rank: 0 },
];
const IMAGE_OPTIONS = [
{
id: "1ddc47be0d2315b9711ee8526ca9d83f",
html: "<img src='upload://tpbXHFLPCTLWjyGvtyekmXQN49A.jpeg'></img>",
votes: 0,
rank: 0,
},
{
id: "70e743697dac09483d7b824eaadb91e1",
html: "<img src='upload://eurierXHFETLWjHsdfLKKJDFLKJ.jpeg'></img>",
votes: 0,
rank: 0,
},
];
module("Poll | Component | poll-options", function (hooks) {
setupRenderingTest(hooks);
@ -80,4 +95,21 @@ module("Poll | Component | poll-options", function (hooks) {
assert.strictEqual(count("li .d-icon-far-check-square:nth-of-type(1)"), 1);
});
test("single with images", async function (assert) {
this.setProperties({
isCheckbox: false,
options: IMAGE_OPTIONS,
votes: [],
});
await render(hbs`<PollOptions
@isCheckbox={{this.isCheckbox}}
@options={{this.options}}
@votes={{this.votes}}
@sendRadioClick={{this.toggleOption}}
/>`);
assert.strictEqual(count("li img"), 2);
});
});