@@ -363,7 +363,7 @@ function element(state, unsafe) {
363
363
let safeElement = false
364
364
365
365
if (
366
- name . length > 0 &&
366
+ name &&
367
367
name !== '*' &&
368
368
( ! state . schema . tagNames || state . schema . tagNames . includes ( name ) )
369
369
) {
@@ -511,21 +511,20 @@ function properties(state, properties) {
511
511
512
512
for ( key in props ) {
513
513
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
+ }
525
525
526
- if ( safe !== null && safe !== undefined ) {
527
- result [ key ] = safe
528
- }
526
+ if ( safe !== null && safe !== undefined ) {
527
+ result [ key ] = safe
529
528
}
530
529
}
531
530
}
@@ -543,6 +542,28 @@ function properties(state, properties) {
543
542
return result
544
543
}
545
544
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
+
546
567
/**
547
568
* Sanitize a property value which is a list.
548
569
*
@@ -557,13 +578,13 @@ function properties(state, properties) {
557
578
* @returns {Array<number | string> }
558
579
* Safe value.
559
580
*/
560
- function propertyValues ( state , definition , key , values ) {
581
+ function propertyValueMany ( state , definition , key , values ) {
561
582
let index = - 1
562
583
/** @type {Array<number | string> } */
563
584
const result = [ ]
564
585
565
586
while ( ++ index < values . length ) {
566
- const value = propertyValue ( state , definition , key , values [ index ] )
587
+ const value = propertyValuePrimitive ( state , definition , key , values [ index ] )
567
588
568
589
if ( typeof value === 'number' || typeof value === 'string' ) {
569
590
result . push ( value )
@@ -574,7 +595,7 @@ function propertyValues(state, definition, key, values) {
574
595
}
575
596
576
597
/**
577
- * Sanitize a property value.
598
+ * Sanitize a property value which is a primitive .
578
599
*
579
600
* @param {State } state
580
601
* Info passed around.
@@ -587,7 +608,7 @@ function propertyValues(state, definition, key, values) {
587
608
* @returns {boolean | number | string | undefined }
588
609
* Safe value.
589
610
*/
590
- function propertyValue ( state , definition , key , value ) {
611
+ function propertyValuePrimitive ( state , definition , key , value ) {
591
612
if (
592
613
typeof value !== 'boolean' &&
593
614
typeof value !== 'number' &&
@@ -713,7 +734,7 @@ function patch(node, unsafe) {
713
734
714
735
/**
715
736
*
716
- * @param {Readonly<Array<PropertyDefinition>> } definitions
737
+ * @param {Readonly<Array<PropertyDefinition>> | undefined } definitions
717
738
* @param {string } key
718
739
* @returns {Readonly<PropertyDefinition> | undefined }
719
740
*/
@@ -722,15 +743,17 @@ function findDefinition(definitions, key) {
722
743
let dataDefault
723
744
let index = - 1
724
745
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 ]
728
750
729
- if ( name === key ) {
730
- return entry
731
- }
751
+ if ( name === key ) {
752
+ return entry
753
+ }
732
754
733
- if ( name === 'data*' ) dataDefault = entry
755
+ if ( name === 'data*' ) dataDefault = entry
756
+ }
734
757
}
735
758
736
759
if ( key . length > 4 && key . slice ( 0 , 4 ) . toLowerCase ( ) === 'data' ) {
0 commit comments