Skip to content

Commit

Permalink
Switch sanitization to a Set and add cleanup
Browse files Browse the repository at this point in the history
This fixes #20.
  • Loading branch information
developit authored Jul 21, 2022
1 parent 96fe21e commit 8679db8
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/vhtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@ let DOMAttributeNames = {
htmlFor: 'for'
};

let sanitized = {};
let sanitized = new Set();

let cleanupTimer = 0;
function cleanup() {
cleanupTimer = 0;
sanitized.clear();
}
function scheduleCleanup() {
if (!cleanupTimer) cleanupTimer = setTimeout(cleanup);
}

/** Hyperscript reviver that constructs a sanitized HTML string. */
export default function h(name, attrs) {
Expand Down Expand Up @@ -47,14 +56,15 @@ export default function h(name, attrs) {
for (let i=child.length; i--; ) stack.push(child[i]);
}
else {
s += sanitized[child]===true ? child : esc(child);
s += sanitized.has(child) ? child : esc(child);
}
}
}

s += name ? `</${name}>` : '';
}

sanitized[s] = true;
sanitized.add(s);
scheduleCleanup();
return s;
}

0 comments on commit 8679db8

Please sign in to comment.