@@ -421,8 +421,8 @@ export class SAXParser {
421421 let char : string = String . fromCodePoint ( code ) ;
422422 this . contentHandler ! . characters ( char ) ;
423423 } else {
424- // Look up entity in DTD using grammar interface
425- const entityValue : string | undefined = grammar . resolveEntity ( name ) ;
424+ // Look up entity in grammar, loading external content if necessary
425+ const entityValue : string | undefined = this . grammarHandler . resolveEntityValue ( name ) ;
426426 if ( entityValue !== undefined ) {
427427 if ( entityValue . length > 0 ) {
428428 if ( entityValue . length === 1 ) {
@@ -1410,7 +1410,7 @@ export class SAXParser {
14101410 && attributeInfo . use !== AttributeUse . REQUIRED ) {
14111411 const targetName : string = this . buildAttributeNameForInfo ( attributeInfo ) ;
14121412 if ( ! result . has ( targetName ) ) {
1413- const defaultValue : string = this . normalizeAttributeByType ( attributeInfo . defaultValue , attributeInfo . datatype ) ;
1413+ const defaultValue : string = this . processDefaultAttributeValue ( attributeInfo ) ;
14141414 result . set ( targetName , defaultValue ) ;
14151415 metadata . set ( targetName , {
14161416 specified : false
@@ -1435,6 +1435,24 @@ export class SAXParser {
14351435 }
14361436 }
14371437
1438+ private processDefaultAttributeValue ( attributeInfo : AttributeInfo ) : string {
1439+ const rawDefault : string = attributeInfo . defaultValue ?? '' ;
1440+
1441+ let normalizedLiteral : string = rawDefault ;
1442+ if ( rawDefault . indexOf ( '\r' ) !== - 1 || rawDefault . indexOf ( '\n' ) !== - 1 ) {
1443+ normalizedLiteral = this . normalizeLiteralAttributeLineBreaks ( rawDefault , rawDefault ) ;
1444+ }
1445+
1446+ if ( rawDefault . includes ( '&' ) ) {
1447+ this . validateAttributeValueWellFormedness ( rawDefault ) ;
1448+ }
1449+
1450+ let expandedValue : string = this . expandEntities ( normalizedLiteral ) ;
1451+ this . validateAttributeCharacterSet ( expandedValue ) ;
1452+
1453+ return this . normalizeAttributeByType ( expandedValue , attributeInfo . datatype ) ;
1454+ }
1455+
14381456 private shouldPreserveLexicalWhitespace ( lexicalValue : string ) : boolean {
14391457 const pattern : RegExp = / & # ( x ? [ 0 - 9 A - F a - f ] + ) ; / g;
14401458 let match : RegExpExecArray | null ;
@@ -1772,7 +1790,7 @@ export class SAXParser {
17721790 }
17731791
17741792 // Look up custom entity using Grammar interface
1775- const entityValue : string | undefined = this . grammarHandler . getGrammar ( ) . resolveEntity ( entityName ) ;
1793+ const entityValue : string | undefined = this . grammarHandler . resolveEntityValue ( entityName ) ;
17761794 if ( entityValue !== undefined ) {
17771795 if ( entityValue !== '' ) {
17781796 // Mark this entity as visited for recursion detection
0 commit comments