Skip to content

Commit

Permalink
fix(demo): escape strings before dom insertion
Browse files Browse the repository at this point in the history
  • Loading branch information
kumavis committed Dec 12, 2023
1 parent c1f1165 commit e946e3d
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion demo/tree/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,17 @@ export default function tree(src, dst, limit) {
return tree;
}

function escape(htmlStr) {
return htmlStr.replaceAll(/&/g, "&")
.replaceAll(/</g, "&lt;")
.replaceAll(/>/g, "&gt;")
.replaceAll(/"/g, "&quot;")
.replaceAll(/'/g, "&#39;");
}

export function showResult (treeString) {
const display = document.createElement('pre');
display.innerHTML = treeString;
display.innerHTML = escape(treeString);
document.body.appendChild(display)
console.log(treeString);
}

0 comments on commit e946e3d

Please sign in to comment.