Skip to content

Commit

Permalink
Fix code scanning alert no. 1: DOM text reinterpreted as HTML
Browse files Browse the repository at this point in the history
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
  • Loading branch information
puria and github-advanced-security[bot] authored Dec 13, 2024
1 parent 8ceadf2 commit b5d6d12
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/webcomponents.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
import { zencode_exec } from "zenroom";
import { SS, LS, stringify } from "./utils";

function escapeHtml(unsafe) {
return unsafe
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#039;");
}

export class Zencode extends HTMLElement {
constructor() {
super();
Expand Down Expand Up @@ -52,9 +61,9 @@ export class BrutalistCard extends HTMLElement {
}

render() {
const title = this.getAttribute("title") || "";
const content = this.getAttribute("content") || "";
const description = this.getAttribute("description") || "";
const title = escapeHtml(this.getAttribute("title") || "");
const content = escapeHtml(this.getAttribute("content") || "");
const description = escapeHtml(this.getAttribute("description") || "");

const isHttps = window.location.protocol === "https:";

Expand Down

0 comments on commit b5d6d12

Please sign in to comment.