@@ -33,16 +33,57 @@ export function createJsxRuntime(): JSX.Runtime {
3333 ) ;
3434 const childrenHtml = createSafeHtmlWithoutSanitize `${ childrenParts . join ( '' ) } ` ;
3535
36+ const isVoidElement = [
37+ 'area' ,
38+ 'base' ,
39+ 'br' ,
40+ 'col' ,
41+ 'embed' ,
42+ 'hr' ,
43+ 'img' ,
44+ 'input' ,
45+ 'link' ,
46+ 'meta' ,
47+ 'source' ,
48+ 'track' ,
49+ 'wbr' ,
50+ ] . includes ( type ) ;
51+
52+ let closePart = createSafeHtmlWithoutSanitize `` ;
53+
54+ if ( isVoidElement ) {
55+ if ( childrenHtml . length > 0 ) {
56+ // eslint-disable-next-line no-console
57+ console . error ( `Element <${ type } > is void element, but has children` , childrenHtml ) ;
58+
59+ closePart = childrenHtml ;
60+ }
61+ } else {
62+ closePart = sanitizeHtml `${ childrenHtml } </${ type } >` ;
63+ }
64+
3665 if ( properties == null ) {
37- return sanitizeHtml `<${ type } >${ childrenHtml } </ ${ type } > ` ;
66+ return sanitizeHtml `<${ type } >${ closePart } ` ;
3867 }
3968
40- const attributesParts : readonly SafeHtml [ ] = Object . entries ( properties ) . map (
41- ( [ key , value ] ) => sanitizeHtml `${ key . toLowerCase ( ) } ="${ value } "` ,
42- ) ;
43- const attributesHtml = createSafeHtmlWithoutSanitize `${ attributesParts . join ( '' ) } ` ;
69+ const attributesParts : readonly SafeHtml [ ] = Object . entries ( properties )
70+ . filter ( ( [ key , value ] ) => {
71+ if ( value == null ) {
72+ return false ;
73+ }
74+
75+ if ( value !== false ) {
76+ return true ;
77+ }
78+
79+ const lowerCaseKey = key . toLocaleLowerCase ( ) ;
80+
81+ return lowerCaseKey . startsWith ( 'aria-' ) || lowerCaseKey . startsWith ( 'data-' ) ;
82+ } )
83+ . map ( ( [ key , value ] ) => sanitizeHtml `${ key . toLowerCase ( ) } ="${ value } "` ) ;
84+ const attributesHtml = createSafeHtmlWithoutSanitize `${ attributesParts . join ( ' ' ) } ` ;
4485
45- return sanitizeHtml `<${ type } ${ attributesHtml } >${ childrenHtml } </ ${ type } > ` ;
86+ return sanitizeHtml `<${ type } ${ attributesHtml } >${ closePart } ` ;
4687 } ;
4788
4889 const Fragment : JSX . Fragment = ( properties ) => {
0 commit comments