Skip to content

Commit 04e12ea

Browse files
committed
refactor: add check of native element for safe element handling
1 parent 87ac0ec commit 04e12ea

File tree

3 files changed

+119
-2
lines changed

3 files changed

+119
-2
lines changed

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
UNSAFE_NAME,
55
NAMESPACE_REPLACE_REGEX,
66
HTML_LOWER_CASE,
7+
HTML_ELEMENTS,
78
HTML_ENUMERATED,
89
SVG_CAMEL_CASE,
910
createComponent,
@@ -666,7 +667,7 @@ function _renderToString(
666667
? 'panose-1'
667668
: name.replace(/([A-Z])/g, '-$1').toLowerCase();
668669
}
669-
} else if (HTML_LOWER_CASE.has(name)) {
670+
} else if (HTML_ELEMENTS.has(type) && HTML_LOWER_CASE.has(name)) {
670671
name = name.toLowerCase();
671672
}
672673
}

src/lib/util.js

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,121 @@
11
import { DIRTY, BITS } from './constants';
22

33
export const VOID_ELEMENTS = /^(?:area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/;
4+
5+
export const HTML_ELEMENTS = new Set([
6+
'a',
7+
'abbr',
8+
'address',
9+
'area',
10+
'article',
11+
'aside',
12+
'audio',
13+
'b',
14+
'base',
15+
'bdi',
16+
'bdo',
17+
'blockquote',
18+
'body',
19+
'br',
20+
'button',
21+
'canvas',
22+
'caption',
23+
'cite',
24+
'code',
25+
'col',
26+
'colgroup',
27+
'data',
28+
'datalist',
29+
'dd',
30+
'del',
31+
'details',
32+
'dfn',
33+
'dialog',
34+
'div',
35+
'dl',
36+
'dt',
37+
'em',
38+
'embed',
39+
'fieldset',
40+
'figcaption',
41+
'figure',
42+
'footer',
43+
'form',
44+
'h1',
45+
'h2',
46+
'h3',
47+
'h4',
48+
'h5',
49+
'h6',
50+
'head',
51+
'header',
52+
'hgroup',
53+
'hr',
54+
'html',
55+
'i',
56+
'iframe',
57+
'img',
58+
'input',
59+
'ins',
60+
'kbd',
61+
'label',
62+
'legend',
63+
'li',
64+
'link',
65+
'main',
66+
'map',
67+
'mark',
68+
'menu',
69+
'meta',
70+
'meter',
71+
'nav',
72+
'noscript',
73+
'object',
74+
'ol',
75+
'optgroup',
76+
'option',
77+
'output',
78+
'p',
79+
'picture',
80+
'pre',
81+
'progress',
82+
'q',
83+
'rp',
84+
'rt',
85+
'ruby',
86+
's',
87+
'samp',
88+
'script',
89+
'search',
90+
'section',
91+
'select',
92+
'slot',
93+
'small',
94+
'source',
95+
'span',
96+
'strong',
97+
'style',
98+
'sub',
99+
'summary',
100+
'sup',
101+
'table',
102+
'tbody',
103+
'td',
104+
'template',
105+
'textarea',
106+
'tfoot',
107+
'th',
108+
'thead',
109+
'time',
110+
'title',
111+
'tr',
112+
'track',
113+
'u',
114+
'ul',
115+
'var',
116+
'video',
117+
'wbr'
118+
]);
4119
// oxlint-disable-next-line no-control-regex
5120
export const UNSAFE_NAME = /[\s\n\\/='"\0<>]/;
6121
export const NAMESPACE_REPLACE_REGEX = /^(xlink|xmlns|xml)([A-Z])/;

src/pretty.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
SVG_CAMEL_CASE,
1212
HTML_ENUMERATED,
1313
HTML_LOWER_CASE,
14+
HTML_ELEMENTS,
1415
getContext,
1516
setDirty,
1617
isDirty,
@@ -299,7 +300,7 @@ function _renderToStringPretty(
299300
? 'panose-1'
300301
: name.replace(/([A-Z])/g, '-$1').toLowerCase();
301302
}
302-
} else if (HTML_LOWER_CASE.has(name)) {
303+
} else if (HTML_ELEMENTS.has(nodeName) && HTML_LOWER_CASE.has(name)) {
303304
name = name.toLowerCase();
304305
}
305306

0 commit comments

Comments
 (0)