@@ -363,7 +363,7 @@ function element(state, unsafe) {
363363 let safeElement = false
364364
365365 if (
366- name . length > 0 &&
366+ name &&
367367 name !== '*' &&
368368 ( ! state . schema . tagNames || state . schema . tagNames . includes ( name ) )
369369 ) {
@@ -511,21 +511,20 @@ function properties(state, properties) {
511511
512512 for ( key in props ) {
513513 if ( own . call ( props , key ) ) {
514- /** @type { Readonly<PropertyDefinition> | undefined } */
515- let definition
516-
517- if ( specific ) definition = findDefinition ( specific , key )
518- if ( ! definition && defaults ) definition = findDefinition ( defaults , key )
519-
520- if ( definition ) {
521- const unsafe = props [ key ]
522- const safe = Array . isArray ( unsafe )
523- ? propertyValues ( state , definition , key , unsafe )
524- : propertyValue ( state , definition , key , unsafe )
514+ const unsafe = props [ key ]
515+ let safe = propertyValue (
516+ state ,
517+ findDefinition ( specific , key ) ,
518+ key ,
519+ unsafe
520+ )
521+
522+ if ( safe === null || safe === undefined ) {
523+ safe = propertyValue ( state , findDefinition ( defaults , key ) , key , unsafe )
524+ }
525525
526- if ( safe !== null && safe !== undefined ) {
527- result [ key ] = safe
528- }
526+ if ( safe !== null && safe !== undefined ) {
527+ result [ key ] = safe
529528 }
530529 }
531530 }
@@ -543,6 +542,28 @@ function properties(state, properties) {
543542 return result
544543}
545544
545+ /**
546+ * Sanitize a property value.
547+ *
548+ * @param {State } state
549+ * Info passed around.
550+ * @param {Readonly<PropertyDefinition> | undefined } definition
551+ * Definition.
552+ * @param {string } key
553+ * Field name.
554+ * @param {Readonly<unknown> } value
555+ * Unsafe value (but an array).
556+ * @returns {Array<number | string> | boolean | number | string | undefined }
557+ * Safe value.
558+ */
559+ function propertyValue ( state , definition , key , value ) {
560+ return definition
561+ ? Array . isArray ( value )
562+ ? propertyValueMany ( state , definition , key , value )
563+ : propertyValuePrimitive ( state , definition , key , value )
564+ : undefined
565+ }
566+
546567/**
547568 * Sanitize a property value which is a list.
548569 *
@@ -557,13 +578,13 @@ function properties(state, properties) {
557578 * @returns {Array<number | string> }
558579 * Safe value.
559580 */
560- function propertyValues ( state , definition , key , values ) {
581+ function propertyValueMany ( state , definition , key , values ) {
561582 let index = - 1
562583 /** @type {Array<number | string> } */
563584 const result = [ ]
564585
565586 while ( ++ index < values . length ) {
566- const value = propertyValue ( state , definition , key , values [ index ] )
587+ const value = propertyValuePrimitive ( state , definition , key , values [ index ] )
567588
568589 if ( typeof value === 'number' || typeof value === 'string' ) {
569590 result . push ( value )
@@ -574,7 +595,7 @@ function propertyValues(state, definition, key, values) {
574595}
575596
576597/**
577- * Sanitize a property value.
598+ * Sanitize a property value which is a primitive .
578599 *
579600 * @param {State } state
580601 * Info passed around.
@@ -587,7 +608,7 @@ function propertyValues(state, definition, key, values) {
587608 * @returns {boolean | number | string | undefined }
588609 * Safe value.
589610 */
590- function propertyValue ( state , definition , key , value ) {
611+ function propertyValuePrimitive ( state , definition , key , value ) {
591612 if (
592613 typeof value !== 'boolean' &&
593614 typeof value !== 'number' &&
@@ -713,7 +734,7 @@ function patch(node, unsafe) {
713734
714735/**
715736 *
716- * @param {Readonly<Array<PropertyDefinition>> } definitions
737+ * @param {Readonly<Array<PropertyDefinition>> | undefined } definitions
717738 * @param {string } key
718739 * @returns {Readonly<PropertyDefinition> | undefined }
719740 */
@@ -722,15 +743,17 @@ function findDefinition(definitions, key) {
722743 let dataDefault
723744 let index = - 1
724745
725- while ( ++ index < definitions . length ) {
726- const entry = definitions [ index ]
727- const name = typeof entry === 'string' ? entry : entry [ 0 ]
746+ if ( definitions ) {
747+ while ( ++ index < definitions . length ) {
748+ const entry = definitions [ index ]
749+ const name = typeof entry === 'string' ? entry : entry [ 0 ]
728750
729- if ( name === key ) {
730- return entry
731- }
751+ if ( name === key ) {
752+ return entry
753+ }
732754
733- if ( name === 'data*' ) dataDefault = entry
755+ if ( name === 'data*' ) dataDefault = entry
756+ }
734757 }
735758
736759 if ( key . length > 4 && key . slice ( 0 , 4 ) . toLowerCase ( ) === 'data' ) {
0 commit comments