Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace innerHTML with Trusted Types friendly ways #821

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
22 changes: 11 additions & 11 deletions src/html5-qrcode-scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export class Html5QrcodeScanner {
if (!container) {
throw `HTML Element with id=${this.elementId} not found`;
}
container.innerHTML = "";
container.textContent = "";
this.createBasicLayout(container!);
this.html5Qrcode = new Html5Qrcode(
this.getScanRegionId(),
Expand Down Expand Up @@ -336,7 +336,7 @@ export class Html5QrcodeScanner {
const emptyHtmlContainer = () => {
const mainContainer = document.getElementById(this.elementId);
if (mainContainer) {
mainContainer.innerHTML = "";
mainContainer.textContent = "";
this.resetBasicLayout(mainContainer);
}
}
Expand Down Expand Up @@ -1047,15 +1047,15 @@ export class Html5QrcodeScanner {
this.getScanRegionId())!;

if (this.cameraScanImage) {
qrCodeScanRegion.innerHTML = "<br>";
qrCodeScanRegion.appendChild(this.cameraScanImage);
const br = document.createElement("br");
qrCodeScanRegion.replaceChildren(br, this.cameraScanImage);
return;
}

this.cameraScanImage = new Image;
this.cameraScanImage.onload = (_) => {
qrCodeScanRegion.innerHTML = "<br>";
qrCodeScanRegion.appendChild($this.cameraScanImage!);
const br = document.createElement("br");
qrCodeScanRegion.replaceChildren(br, $this.cameraScanImage!);
}
this.cameraScanImage.width = 64;
this.cameraScanImage.style.opacity = "0.8";
Expand All @@ -1069,15 +1069,15 @@ export class Html5QrcodeScanner {
this.getScanRegionId())!;

if (this.fileScanImage) {
qrCodeScanRegion.innerHTML = "<br>";
qrCodeScanRegion.appendChild(this.fileScanImage);
const br = document.createElement("br");
qrCodeScanRegion.replaceChildren(br, this.fileScanImage);
return;
}

this.fileScanImage = new Image;
this.fileScanImage.onload = (_) => {
qrCodeScanRegion.innerHTML = "<br>";
qrCodeScanRegion.appendChild($this.fileScanImage!);
const br = document.createElement("br");
qrCodeScanRegion.replaceChildren(br, $this.fileScanImage!);
}
this.fileScanImage.width = 64;
this.fileScanImage.style.opacity = "0.8";
Expand All @@ -1088,7 +1088,7 @@ export class Html5QrcodeScanner {
private clearScanRegion() {
const qrCodeScanRegion = document.getElementById(
this.getScanRegionId())!;
qrCodeScanRegion.innerHTML = "";
qrCodeScanRegion.textContent = "";
}

//#region state getters
Expand Down
2 changes: 1 addition & 1 deletion src/html5-qrcode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1380,7 +1380,7 @@ export class Html5Qrcode {
}
const element = document.getElementById(this.elementId);
if (element) {
element.innerHTML = "";
element.textContent = "";
}
}

Expand Down
10 changes: 5 additions & 5 deletions tests/ui/scanner/camera-selection-ui.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe("CameraSelectionUi#create()", () => {

after(() => {
document.body.removeChild(parentElement!);
parentElement!.innerHTML = "";
parentElement!.textContent = "";
parentElement = undefined;
});

Expand All @@ -40,7 +40,7 @@ describe("CameraSelectionUi#create()", () => {
});

it("Single cameras, creates the camera selection", () => {
parentElement!.innerHTML = "";
parentElement!.textContent = "";
let numCameras = 1;
let cameras = createCameraList(numCameras);
let cameraSelectUi = CameraSelectionUi.create(parentElement!, cameras);
Expand All @@ -58,7 +58,7 @@ describe("CameraSelectionUi#create()", () => {
let cameras = createCameraList(numCameras);
expect(() => {
let _ = CameraSelectionUi.create(parentElement!, cameras);
}).to.throw();
}).to.throw();
});
});

Expand All @@ -72,7 +72,7 @@ describe("CameraSelectionUi#enable() & disable()", () => {

after(() => {
document.body.removeChild(parentElement!);
parentElement!.innerHTML = "";
parentElement!.textContent = "";
parentElement = undefined;
});

Expand Down Expand Up @@ -113,7 +113,7 @@ describe("CameraSelectionUi setting and getting values", () => {

after(() => {
document.body.removeChild(parentElement!);
parentElement!.innerHTML = "";
parentElement!.textContent = "";
parentElement = undefined;
});

Expand Down