From 6255591db201543c0553e47a3beb9830a8442c87 Mon Sep 17 00:00:00 2001 From: Ryan Christian Date: Sat, 14 Sep 2024 06:51:46 -0500 Subject: [PATCH] refactor: Switch to a Set --- src/index.js | 2 +- src/lib/util.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 8917a77..c648b4f 100644 --- a/src/index.js +++ b/src/index.js @@ -625,7 +625,7 @@ function _renderToString( } else if (UNSAFE_NAME.test(name)) { continue; } else if ( - (name[4] === '-' || HTML_ENUMERATED.test(name)) && + (name[4] === '-' || HTML_ENUMERATED.has(name)) && v != null ) { // serialize boolean aria-xyz or enumerated attribute values as strings diff --git a/src/lib/util.js b/src/lib/util.js index 19f874b..84b348d 100644 --- a/src/lib/util.js +++ b/src/lib/util.js @@ -2,9 +2,11 @@ export const VOID_ELEMENTS = /^(?:area|base|br|col|embed|hr|img|input|link|meta| export const UNSAFE_NAME = /[\s\n\\/='"\0<>]/; export const NAMESPACE_REPLACE_REGEX = /^(xlink|xmlns|xml)([A-Z])/; export const HTML_LOWER_CASE = /^accessK|^auto[A-Z]|^cell|^ch|^col|cont|cross|dateT|encT|form[A-Z]|frame|hrefL|inputM|maxL|minL|noV|playsI|popoverT|readO|rowS|src[A-Z]|tabI|useM|item[A-Z]/; -export const HTML_ENUMERATED = /^dra|spel/; export const SVG_CAMEL_CASE = /^ac|^ali|arabic|basel|cap|clipPath$|clipRule$|color|dominant|enable|fill|flood|font|glyph[^R]|horiz|image|letter|lighting|marker[^WUH]|overline|panose|pointe|paint|rendering|shape|stop|strikethrough|stroke|text[^L]|transform|underline|unicode|units|^v[^i]|^w|^xH/; +// Boolean DOM properties that translate to enumerated ('true'/'false') attributes +export const HTML_ENUMERATED = new Set(['draggable', 'spellcheck']); + // DOM properties that should NOT have "px" added when numeric const ENCODED_ENTITIES = /["&<]/;