mirror of
https://github.com/discourse/discourse.git
synced 2024-11-28 19:53:53 -06:00
DEV: Add aria-label
option to the d-icon
helper (#17741)
Extracted from https://github.com/discourse/discourse/pull/17379.
This commit is contained in:
parent
ce9eec8606
commit
53dd9b0c66
@ -150,6 +150,10 @@ registerIconRenderer({
|
||||
|
||||
if (params.label) {
|
||||
html += " aria-hidden='true'";
|
||||
} else if (params["aria-label"]) {
|
||||
html += ` aria-hidden='false' aria-label='${escape(
|
||||
params["aria-label"]
|
||||
)}'`;
|
||||
}
|
||||
html += ` xmlns="${SVG_NAMESPACE}"><use href="#${id}" /></svg>`;
|
||||
if (params.label) {
|
||||
|
@ -25,15 +25,21 @@ module("Unit | Utility | icon-library", function () {
|
||||
assert.ok(!iconHTML(iconC).includes(" "), "trims whitespace");
|
||||
});
|
||||
|
||||
test("escape icon names, classes and titles", function (assert) {
|
||||
const html = iconHTML("'<img src='x'>", {
|
||||
test("escape icon names, classes, titles and aria-label", function (assert) {
|
||||
let html = iconHTML("'<img src='x'>", {
|
||||
translatedTitle: "'<script src='y'>",
|
||||
label: "<iframe src='z'>",
|
||||
class: "'<link href='w'>",
|
||||
"aria-label": "<script>alert(1)",
|
||||
});
|
||||
assert.ok(html.includes("'<img src='x'>"));
|
||||
assert.ok(html.includes("'<script src='y'>"));
|
||||
assert.ok(html.includes("<iframe src='z'>"));
|
||||
assert.ok(html.includes("'<link href='w'>"));
|
||||
|
||||
html = iconHTML("'<img src='x'>", {
|
||||
"aria-label": "<script>alert(1)",
|
||||
});
|
||||
assert.ok(html.includes("aria-label='<script>alert(1)'"));
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user