From 8679db8ad83316ec066de1b4d766ca3586910974 Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Thu, 21 Jul 2022 09:19:37 -0400 Subject: [PATCH] Switch sanitization to a Set and add cleanup This fixes #20. --- src/vhtml.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/vhtml.js b/src/vhtml.js index 0e03f69..e2bff65 100644 --- a/src/vhtml.js +++ b/src/vhtml.js @@ -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) { @@ -47,7 +56,7 @@ 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); } } } @@ -55,6 +64,7 @@ export default function h(name, attrs) { s += name ? `` : ''; } - sanitized[s] = true; + sanitized.add(s); + scheduleCleanup(); return s; } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy