Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions pxtsim/accessibility.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

// Helpers designed to help to make a simulator accessible.
namespace pxsim.accessibility {
let liveRegion: HTMLDivElement;
let keydownListenerAdded = false;
let addNonBreakingSpace = false;

export function makeFocusable(elem: SVGElement): void {
elem.setAttribute("focusable", "true");
Expand Down Expand Up @@ -73,27 +73,27 @@ namespace pxsim.accessibility {
}

export function setLiveContent(value: string): void {
let liveRegion = document.getElementById("sim-live-region");
if (!liveRegion) {
let style = "position: absolute !important;" +
"display: block;" +
"visibility: visible;" +
"overflow: hidden;" +
"width: 1px;" +
let style = "border: 0;" +
"clip: rect(0, 0, 0, 0);" +
"height: 1px;" +
"margin: -1px;" +
"border: 0;" +
"overflow: hidden;" +
"padding: 0;" +
"clip: rect(0 0 0 0);";
"position: absolute;" +
"width: 1px;";
liveRegion = document.createElement("div");
liveRegion.setAttribute("role", "status");
liveRegion.id = "sim-live-region";
liveRegion.setAttribute("aria-live", "polite");
liveRegion.setAttribute("aria-hidden", "false");
liveRegion.setAttribute("style", style);
document.body.appendChild(liveRegion);
}

if (liveRegion.textContent !== value) {
liveRegion.textContent = value;
if (value) {
/* eslint-disable @microsoft/sdl/no-inner-html */
liveRegion.innerHTML = `<p>${value}${addNonBreakingSpace ? '&nbsp;' : ''}</p>`;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's not use innerhtml here.. are we certain that everything being passed to this function is sanitized? if someone were to, say, pass a malicious string with html into our localization pipeline somehow would they be able to inject some code?

addNonBreakingSpace = !addNonBreakingSpace;
}
}
}