Skip to content

Commit 0dccf5c

Browse files
committed
create starter and finished files for video 83
1 parent 0ba4178 commit 0dccf5c

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { sanitize } from "dompurify";
2+
3+
const input = document.querySelector('[name="input"]');
4+
const output = document.querySelector(".output");
5+
const buttons = document.querySelectorAll("nav button");
6+
input.addEventListener("input", () => {
7+
const clean = sanitize(input.value, {
8+
FORBID_ATTR: ["width", "height", "style"],
9+
FORBID_TAGS: ["style"],
10+
});
11+
output.innerHTML = clean.replace(/\n/g, "<br>");
12+
});
13+
14+
// trigger an input even on page load
15+
input.dispatchEvent(new Event("input"));
16+
17+
buttons.forEach((button) =>
18+
button.addEventListener("click", (e) => {
19+
alert(e.currentTarget.textContent);
20+
})
21+
);

exercises/83 - Security/nasty.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ const input = document.querySelector('[name="input"]');
44
const output = document.querySelector('.output');
55
const buttons = document.querySelectorAll('nav button');
66
input.addEventListener('input', () => {
7-
const clean = sanitize(input.value, {
8-
FORBID_ATTR: ['width', 'height', 'style'],
9-
FORBID_TAGS: ['style'],
10-
});
11-
output.innerHTML = clean.replace(/\n/g, '<br>');
7+
output.innerHTML = input.value.replace(/\n/g, '<br>');
128
});
139

1410
// trigger an input even on page load

0 commit comments

Comments
 (0)