diff --git a/api/slimdom.api.json b/api/slimdom.api.json index b2e36c4..98a83b4 100644 --- a/api/slimdom.api.json +++ b/api/slimdom.api.json @@ -1,7 +1,7 @@ { "metadata": { "toolPackage": "@microsoft/api-extractor", - "toolVersion": "7.42.3", + "toolVersion": "7.43.0", "schemaVersion": 1011, "oldestForwardsCompatibleVersion": 1001, "tsdocConfig": { diff --git a/src/dom-parsing/parsingAlgorithms.ts b/src/dom-parsing/parsingAlgorithms.ts index 19d21a2..4d4f245 100644 --- a/src/dom-parsing/parsingAlgorithms.ts +++ b/src/dom-parsing/parsingAlgorithms.ts @@ -53,7 +53,7 @@ function offsetToCoords(input: string, offset: number): { line: number; char: nu function replaceInvalidCharacters(input: string): string { return Array.from(input, (char) => - matchesCharProduction(char) ? char : '[invalid character]' + matchesCharProduction(char) ? char : '[invalid character]', ).join(''); } @@ -83,21 +83,21 @@ function highlightError(input: string, start: number, end: number): string { const inside = truncate( replaceInvalidCharacters(input.substring(start, end)), TruncateSide.Inside, - 30 + 30, ); const newlineIndexBefore = input.lastIndexOf('\n', start); const lineBefore = truncate( replaceInvalidCharacters(input.substring(newlineIndexBefore + 1, start)), TruncateSide.Start, - 55 - inside.length + 55 - inside.length, ); const newlineIndexAfter = input.indexOf('\n', end); const lineAfter = truncate( replaceInvalidCharacters( - newlineIndexAfter > 0 ? input.substring(end, newlineIndexAfter) : input.substring(end) + newlineIndexAfter > 0 ? input.substring(end, newlineIndexAfter) : input.substring(end), ), TruncateSide.End, - 80 - inside.length - lineBefore.length + 80 - inside.length - lineBefore.length, ); const indent = Array.from(lineBefore, (c) => (isWhitespace(c) ? c : ' ')).join(''); const squiggle = '^'.repeat(Math.max(Array.from(inside).length, 1)); @@ -108,13 +108,13 @@ export function throwErrorWithContext(message: string, event: WithPosition - str.includes('"') ? `'${str}'` : `"${str}"` + str.includes('"') ? `'${str}'` : `"${str}"`, ); const cp = input.codePointAt(offset); const actual = cp ? String.fromCodePoint(cp) : ''; @@ -122,7 +122,7 @@ function throwParseError(what: string, input: string, expected: string[], offset `Parsing ${what} failed, expected ${ quoted.length > 1 ? 'one of ' + quoted.join(', ') : quoted[0] }`, - { input, start: offset, end: offset + Math.max(actual.length, 1) } + { input, start: offset, end: offset + Math.max(actual.length, 1) }, ); } @@ -190,7 +190,7 @@ function constructReplacementText(value: EntityValueEvent[]): string { case ParserEventType.PEReference: throwErrorWithContext( `reference to parameter entity "${event.name}" must not occur in an entity declaration in the internal subset`, - event + event, ); } } @@ -230,13 +230,13 @@ class Dtd { ) { throwErrorWithContext( `default value of attribute "${attr.name.name}" contains reference to undefined entity "${event.name}"`, - event + event, ); } if (this._externalEntityNames.has(event.name)) { throwErrorWithContext( `default value of attribute "${attr.name.name}" must not contain reference to external entity "${event.name}"`, - event + event, ); } } @@ -269,7 +269,7 @@ class Dtd { ) { throwErrorWithContext( `reference to parameter entity "${event.name}" must not occur in an entity declaration in the internal subset`, - event + event, ); } } @@ -288,7 +288,7 @@ class Dtd { if (Array.isArray(decl.value)) { this._entityReplacementTextByName.set( decl.name, - constructReplacementText(decl.value) + constructReplacementText(decl.value), ); } else if (decl.value.ndata === null) { // External parsed entity may be skipped @@ -308,14 +308,14 @@ class Dtd { public getEntityReplacementText( event: EntityRefEvent, - allowExternal: boolean + allowExternal: boolean, ): string | undefined { const value = this._entityReplacementTextByName.get(event.name); if (value === undefined) { if (this._unparsedEntityNames.has(event.name)) { throwErrorWithContext( `reference to binary entity "${event.name}" is not allowed`, - event + event, ); } if (this._externalEntityNames.has(event.name)) { @@ -324,7 +324,7 @@ class Dtd { } throwErrorWithContext( `reference to external entity "${event.name}" is not allowed in attribute value`, - event + event, ); } } @@ -345,7 +345,7 @@ function normalizeAndIncludeEntities( value: AttValueEvent[], dtd: Dtd | null, ancestorEntities: string[] | null, - expansionGuard: EntityExpansionGuard + expansionGuard: EntityExpansionGuard, ) { for (const event of value) { if (typeof event === 'string') { @@ -361,7 +361,7 @@ function normalizeAndIncludeEntities( if (ancestorEntities !== null && ancestorEntities.includes(event.name)) { throwErrorWithContext( `reference to entity "${event.name}" must not be recursive`, - event + event, ); } let replacementText = predefinedEntitiesReplacementText.get(event.name); @@ -371,7 +371,7 @@ function normalizeAndIncludeEntities( if (replacementText === undefined) { throwErrorWithContext( `reference to unknown entity "${event.name}" in attribute value`, - event + event, ); } expansionGuard.enter(event, replacementText.length); @@ -381,7 +381,7 @@ function normalizeAndIncludeEntities( `replacement text for entity "${event.name}"`, replacementText, result.expected, - result.offset + result.offset, ); } // Recursively normalize replacement text @@ -390,7 +390,7 @@ function normalizeAndIncludeEntities( result.value, dtd, ancestorEntities ? [event.name, ...ancestorEntities] : [event.name], - expansionGuard + expansionGuard, ); expansionGuard.exit(); } @@ -400,7 +400,7 @@ function normalizeAttributeValue( value: AttValueEvent[], attDef: AttDefEvent | undefined, dtd: Dtd | null, - expansionGuard: EntityExpansionGuard + expansionGuard: EntityExpansionGuard, ): string { const normalized: string[] = []; normalizeAndIncludeEntities(normalized, value, dtd, null, expansionGuard); @@ -418,7 +418,7 @@ type QualifiedNameCache = Map; function splitQualifiedName( event: WithPosition<{ name: string }>, - cache: QualifiedNameCache + cache: QualifiedNameCache, ): QualifiedNameParts { const qualifiedName = event.name; const fromCache = cache.get(qualifiedName); @@ -458,7 +458,7 @@ class Namespaces { private constructor( parent: Namespaces | null, - resolve: ((prefix: string) => string | undefined) | null = null + resolve: ((prefix: string) => string | undefined) | null = null, ) { this._parent = parent; this._resolve = resolve ?? parent?._resolve ?? null; @@ -486,7 +486,7 @@ class Namespaces { public getForAttribute( prefix: string | null, localName: string, - event: WithPosition + event: WithPosition, ): string | null { if (prefix === null) { // Default namespace doesn't apply to attributes @@ -513,7 +513,7 @@ class Namespaces { attlist: Map | undefined, dtd: Dtd | null, qualifiedNameCache: QualifiedNameCache, - expansionGuard: EntityExpansionGuard + expansionGuard: EntityExpansionGuard, ): Namespaces { let ns = parent; let hasDeclarations = false; @@ -521,30 +521,30 @@ class Namespaces { const add = ( prefix: string | null, namespace: string | null, - event: WithPosition + event: WithPosition, ) => { if (prefix === null && (namespace === XML_NAMESPACE || namespace === XMLNS_NAMESPACE)) { throwErrorWithContext( `the namespace "${namespace}" must not be used as the default namespace`, - event + event, ); } if (namespace === XMLNS_NAMESPACE) { throwErrorWithContext( `the namespace "${XMLNS_NAMESPACE}" must not be bound to a prefix`, - event + event, ); } if (namespace === XML_NAMESPACE && prefix !== 'xml') { throwErrorWithContext( `the namespace "${XML_NAMESPACE}" must be bound only to the prefix "xml"`, - event + event, ); } if (namespace !== XML_NAMESPACE && prefix === 'xml') { throwErrorWithContext( `the xml namespace prefix must not be bound to any namespace other than "${XML_NAMESPACE}"`, - event + event, ); } if (prefix !== null && namespace === null) { @@ -571,7 +571,7 @@ class Namespaces { if (localName === 'xmlns') { throwErrorWithContext( 'the "xmlns" namespace prefix must not be declared', - nameEvent + nameEvent, ); } const namespace = normalizeAttributeValue(value, def, dtd, expansionGuard) || null; @@ -624,8 +624,7 @@ type DomContext = { parent: DomContext | null; root: Node; namespaces: Namespaces; - entityRoot: boolean; -}; +} & ({ entityRoot: true } | { entityRoot: false; event: STagEvent }); type EntityContext = { parent: EntityContext | null; @@ -694,7 +693,7 @@ export function parseXml( entityExpansionMaxAmplification = DEFAULT_ENTITY_EXPANSION_MAX_AMPLIFICATION, entityExpansionThreshold = DEFAULT_ENTITY_EXPANSION_THRESHOLD, treatCDataAsText = false, - }: ParseOptions + }: ParseOptions, ): void { const doc = getNodeDocument(into); let domContext: DomContext = { @@ -729,7 +728,7 @@ export function parseXml( const expansionGuard = new EntityExpansionGuard( input.length, entityExpansionThreshold, - entityExpansionMaxAmplification + entityExpansionMaxAmplification, ); let entityContext: EntityContext | null = { parent: null, @@ -750,7 +749,7 @@ export function parseXml( if (domContext.root === doc && doc.documentElement !== null) { throwErrorWithContext( 'character reference must not appear after the document element', - event + event, ); } collectedText.push(String.fromCodePoint(event.cp)); @@ -760,14 +759,14 @@ export function parseXml( if (domContext.root === doc && doc.documentElement !== null) { throwErrorWithContext( `reference to entity "${event.name}" must not appear after the document element`, - event + event, ); } for (let ctx: EntityContext | null = entityContext; ctx; ctx = ctx.parent) { if (ctx.entity === event.name) { throwErrorWithContext( `reference to entity "${event.name}" must not be recursive`, - event + event, ); } } @@ -778,7 +777,7 @@ export function parseXml( if (replacementText === undefined) { throwErrorWithContext( `reference to unknown entity "${event.name}" in content`, - event + event, ); } expansionGuard.enter(event, replacementText.length); @@ -811,7 +810,7 @@ export function parseXml( if (domContext.root === doc && doc.documentElement !== null) { throwErrorWithContext( 'CData section must not appear after the document element', - event + event, ); } appendParsedNode(domContext.root, doc.createCDATASection(event.data)); @@ -829,15 +828,15 @@ export function parseXml( doc.implementation.createDocumentType( event.name, event.ids?.publicId || '', - event.ids?.systemId || '' - ) + event.ids?.systemId || '', + ), ); continue; case ParserEventType.PI: appendParsedNode( domContext.root, - doc.createProcessingInstruction(event.target, event.data || '') + doc.createProcessingInstruction(event.target, event.data || ''), ); continue; @@ -846,7 +845,7 @@ export function parseXml( if (domContext.root === doc && doc.documentElement !== null) { throwErrorWithContext( `document must contain a single root element, but found "${doc.documentElement.nodeName}" and "${event.name.name}"`, - event.name + event.name, ); } const attlist = dtd ? dtd.getAttlist(event.name) : undefined; @@ -856,11 +855,11 @@ export function parseXml( attlist, dtd, qualifiedNameCache, - expansionGuard + expansionGuard, ); const { prefix, localName } = splitQualifiedName( event.name, - qualifiedNameCache + qualifiedNameCache, ); const namespace = namespaces.getForElement(prefix, event.name); // We can skip the usual name validity checks @@ -868,14 +867,14 @@ export function parseXml( for (const attr of event.attributes) { const { prefix, localName } = splitQualifiedName( attr.name, - qualifiedNameCache + qualifiedNameCache, ); const namespace = namespaces.getForAttribute(prefix, localName, attr.name); const def = attlist?.get(attr.name.name); if (element.hasAttributeNS(namespace, localName)) { throwErrorWithContext( `attribute "${attr.name.name}" must not appear multiple times on element "${event.name.name}"`, - attr.name + attr.name, ); } // We can skip validation of names and duplicates @@ -884,7 +883,7 @@ export function parseXml( prefix, localName, normalizeAttributeValue(attr.value, def, dtd, expansionGuard), - element + element, ); appendAttribute(attrNode, element, true); } @@ -897,12 +896,12 @@ export function parseXml( } const { prefix, localName } = splitQualifiedName( attr.name, - qualifiedNameCache + qualifiedNameCache, ); const namespace = namespaces.getForAttribute( prefix, localName, - attr.name + attr.name, ); if (element.hasAttributeNS(namespace, localName)) { continue; @@ -913,7 +912,7 @@ export function parseXml( prefix, localName, normalizeAttributeValue(def.value, attr, dtd, expansionGuard), - element + element, ); appendAttribute(attrNode, element, true); } @@ -925,6 +924,7 @@ export function parseXml( root: element, namespaces, entityRoot: false, + event, }; } continue; @@ -938,7 +938,7 @@ export function parseXml( ? `"${domContext.root.nodeName}"` : 'no such tag' }`, - event + event, ); } // The check above means we never leave the document DomContext @@ -952,25 +952,26 @@ export function parseXml( entityContext.entity ? `replacement text for entity ${entityContext.entity}` : into === doc - ? 'document' - : 'fragment', + ? 'document' + : 'fragment', input, it.value.expected, - it.value.offset + it.value.offset, ); } if (!domContext.entityRoot) { - throw new Error( + throwErrorWithContext( `${ entityContext.entity ? `replacement text for entity "${entityContext.entity}"` : into === doc - ? 'document' - : 'fragment' + ? 'document' + : 'fragment' } is not well-formed - element "${ domContext.root.nodeName - }" is missing a closing tag` + }" is missing a closing tag`, + domContext.event.name, ); } @@ -1024,7 +1025,7 @@ export function parseXmlFragment( * @public */ treatCDataAsText: boolean; - }> = {} + }> = {}, ): DocumentFragment { const doc = new Document(); const fragment = doc.createDocumentFragment(); @@ -1035,7 +1036,7 @@ export function parseXmlFragment( ? Namespaces.default(options.resolveNamespacePrefix) : ROOT_NAMESPACES, fragment, - options + options, ); return fragment; } diff --git a/test/dom-parsing/__snapshots__/xmlConformance.tests.ts.snap b/test/dom-parsing/__snapshots__/xmlConformance.tests.ts.snap index 99c2d20..61fb716 100644 --- a/test/dom-parsing/__snapshots__/xmlConformance.tests.ts.snap +++ b/test/dom-parsing/__snapshots__/xmlConformance.tests.ts.snap @@ -1208,7 +1208,13 @@ At line 1, character 31: ^" `; -exports[`XML Conformance Test Suite IBM XML 1.0 Tests not-wf ibm-not-wf-P39-ibm39n01.xml - Tests element with a required field missing. The ETag is missing for the element "root".: ibm-not-wf-P39-ibm39n01.xml 1`] = `"document is not well-formed - element "root" is missing a closing tag"`; +exports[`XML Conformance Test Suite IBM XML 1.0 Tests not-wf ibm-not-wf-P39-ibm39n01.xml - Tests element with a required field missing. The ETag is missing for the element "root".: ibm-not-wf-P39-ibm39n01.xml 1`] = ` +"document is not well-formed - element "root" is missing a closing tag +At line 5, character 2: + +missing end tag + ^^^^" +`; exports[`XML Conformance Test Suite IBM XML 1.0 Tests not-wf ibm-not-wf-P39-ibm39n02.xml - Tests element with a required field missing. The STag is missing for the element "root".: ibm-not-wf-P39-ibm39n02.xml 1`] = ` "Parsing document failed, expected "<" @@ -1218,7 +1224,13 @@ missing start tag ^" `; -exports[`XML Conformance Test Suite IBM XML 1.0 Tests not-wf ibm-not-wf-P39-ibm39n03.xml - Tests element with required fields missing. Both the content and the ETag are missing in the element "root".: ibm-not-wf-P39-ibm39n03.xml 1`] = `"document is not well-formed - element "root" is missing a closing tag"`; +exports[`XML Conformance Test Suite IBM XML 1.0 Tests not-wf ibm-not-wf-P39-ibm39n03.xml - Tests element with required fields missing. Both the content and the ETag are missing in the element "root".: ibm-not-wf-P39-ibm39n03.xml 1`] = ` +"document is not well-formed - element "root" is missing a closing tag +At line 5, character 2: + + + ^^^^" +`; exports[`XML Conformance Test Suite IBM XML 1.0 Tests not-wf ibm-not-wf-P39-ibm39n04.xml - Tests element with required fields missing. Both the content and the STag are missing in the element "root".: ibm-not-wf-P39-ibm39n04.xml 1`] = ` "Parsing document failed, expected "valid name start character" @@ -1406,7 +1418,13 @@ At line 6, character 51: ^" `; -exports[`XML Conformance Test Suite IBM XML 1.0 Tests not-wf ibm-not-wf-P42-ibm42n03.xml - Tests ETag with a wrong beginning sequence. The string "less than" is used as a beginning sequence of the ETag of the element "root".: ibm-not-wf-P42-ibm42n03.xml 1`] = `"document is not well-formed - element "root" is missing a closing tag"`; +exports[`XML Conformance Test Suite IBM XML 1.0 Tests not-wf ibm-not-wf-P42-ibm42n03.xml - Tests ETag with a wrong beginning sequence. The string "less than" is used as a beginning sequence of the ETag of the element "root".: ibm-not-wf-P42-ibm42n03.xml 1`] = ` +"document is not well-formed - element "root" is missing a closing tag +At line 6, character 52: + +…Wrong begining sequence in ETag + ^^^^" +`; exports[`XML Conformance Test Suite IBM XML 1.0 Tests not-wf ibm-not-wf-P42-ibm42n04.xml - Tests ETag with a wrong structure. An white space occurs between The beginning sequence and the Name of the ETag of the element "root".: ibm-not-wf-P42-ibm42n04.xml 1`] = ` "Parsing document failed, expected "valid name start character" @@ -3676,7 +3694,13 @@ At line 4, character 6: ^^^" `; -exports[`XML Conformance Test Suite James Clark XML 1.0 tests not-wf-sa-074 - Internal general parsed entities are only well formed if they match the "content" production.: not-wf-sa-074 1`] = `"replacement text for entity "e" is not well-formed - element "foo" is missing a closing tag"`; +exports[`XML Conformance Test Suite James Clark XML 1.0 tests not-wf-sa-074 - Internal general parsed entities are only well formed if they match the "content" production.: not-wf-sa-074 1`] = ` +"replacement text for entity "e" is not well-formed - element "foo" is missing a closing tag +At line 1, character 8: + + + ^^^" +`; exports[`XML Conformance Test Suite James Clark XML 1.0 tests not-wf-sa-075 - ENTITY can't reference itself directly or indirectly.: not-wf-sa-075 1`] = ` "reference to entity "e1" must not be recursive @@ -3886,9 +3910,21 @@ At line 1, character 19: ^" `; -exports[`XML Conformance Test Suite James Clark XML 1.0 tests not-wf-sa-103 - End-tag required for element foo.: not-wf-sa-103 1`] = `"replacement text for entity "e" is not well-formed - element "foo" is missing a closing tag"`; +exports[`XML Conformance Test Suite James Clark XML 1.0 tests not-wf-sa-103 - End-tag required for element foo.: not-wf-sa-103 1`] = ` +"replacement text for entity "e" is not well-formed - element "foo" is missing a closing tag +At line 1, character 2: -exports[`XML Conformance Test Suite James Clark XML 1.0 tests not-wf-sa-104 - Internal general parsed entities are only well formed if they match the "content" production.: not-wf-sa-104 1`] = `"replacement text for entity "e" is not well-formed - element "foo" is missing a closing tag"`; + + ^^^" +`; + +exports[`XML Conformance Test Suite James Clark XML 1.0 tests not-wf-sa-104 - Internal general parsed entities are only well formed if they match the "content" production.: not-wf-sa-104 1`] = ` +"replacement text for entity "e" is not well-formed - element "foo" is missing a closing tag +At line 1, character 2: + + + ^^^" +`; exports[`XML Conformance Test Suite James Clark XML 1.0 tests not-wf-sa-105 - Invalid placement of CDATA section.: not-wf-sa-105 1`] = ` "Parsing document failed, expected "valid name start character" @@ -4418,7 +4454,13 @@ At line 3, character 15: ^^^^^^^^^^^^^^^^^^^" `; -exports[`XML Conformance Test Suite James Clark XML 1.0 tests not-wf-sa-176 - Start tags must have matching end tags.: not-wf-sa-176 1`] = `"document is not well-formed - element "doc" is missing a closing tag"`; +exports[`XML Conformance Test Suite James Clark XML 1.0 tests not-wf-sa-176 - Start tags must have matching end tags.: not-wf-sa-176 1`] = ` +"document is not well-formed - element "doc" is missing a closing tag +At line 4, character 2: + + + ^^^" +`; exports[`XML Conformance Test Suite James Clark XML 1.0 tests not-wf-sa-177 - Character FFFF is not legal anywhere in an XML document.: not-wf-sa-177 1`] = ` "Parsing document failed, expected "end of input" @@ -4516,7 +4558,13 @@ At line 1, character 8: ^^^" `; -exports[`XML Conformance Test Suite OASIS/NIST XML 1.0 Tests o-p01fail4 - document element must be complete.: o-p01fail4 1`] = `"document is not well-formed - element "doc" is missing a closing tag"`; +exports[`XML Conformance Test Suite OASIS/NIST XML 1.0 Tests o-p01fail4 - document element must be complete.: o-p01fail4 1`] = ` +"document is not well-formed - element "doc" is missing a closing tag +At line 1, character 2: + + + ^^^" +`; exports[`XML Conformance Test Suite OASIS/NIST XML 1.0 Tests o-p02fail1 - Use of illegal character within XML document.: o-p02fail1 1`] = ` "Parsing document failed, expected "end of input" @@ -5438,7 +5486,13 @@ At line 1, character 33: ^" `; -exports[`XML Conformance Test Suite OASIS/NIST XML 1.0 Tests o-p39fail1 - start-tag requires end-tag: o-p39fail1 1`] = `"document is not well-formed - element "doc" is missing a closing tag"`; +exports[`XML Conformance Test Suite OASIS/NIST XML 1.0 Tests o-p39fail1 - start-tag requires end-tag: o-p39fail1 1`] = ` +"document is not well-formed - element "doc" is missing a closing tag +At line 1, character 2: + +content + ^^^" +`; exports[`XML Conformance Test Suite OASIS/NIST XML 1.0 Tests o-p39fail2 - end-tag requires start-tag: o-p39fail2 1`] = ` "non-well-formed element: found end tag "a" but expected "doc" @@ -6891,7 +6945,13 @@ At line 5, character 44: ^" `; -exports[`XML Conformance Test Suite Sun Microsystems XML Tests not-wf sgml01 - SGML-ism: omitted end tag for EMPTY content: sgml01 1`] = `"document is not well-formed - element "root" is missing a closing tag"`; +exports[`XML Conformance Test Suite Sun Microsystems XML Tests not-wf sgml01 - SGML-ism: omitted end tag for EMPTY content: sgml01 1`] = ` +"document is not well-formed - element "root" is missing a closing tag +At line 7, character 2: + + + ^^^^" +`; exports[`XML Conformance Test Suite Sun Microsystems XML Tests not-wf sgml02 - XML declaration must be at the very beginning of a document; it"s not a processing instruction: sgml02 1`] = ` "Parsing document failed, expected 'processing instruction target must not be "xml"' diff --git a/test/dom-parsing/parseXmlDocument.tests.ts b/test/dom-parsing/parseXmlDocument.tests.ts index 8e0734b..bd22acb 100644 --- a/test/dom-parsing/parseXmlDocument.tests.ts +++ b/test/dom-parsing/parseXmlDocument.tests.ts @@ -77,7 +77,7 @@ describe('parseXmlDocument', () => { const doc = slimdom.parseXmlDocument(xml); expect(doc.documentElement?.namespaceURI).toBe('ns1'); expect( - doc.documentElement?.firstElementChild?.getAttributeNode('pre:attr')?.namespaceURI + doc.documentElement?.firstElementChild?.getAttributeNode('pre:attr')?.namespaceURI, ).toBe('ns2'); expect(doc.documentElement?.firstElementChild?.firstElementChild?.namespaceURI).toBe('ns3'); expect(doc.getElementsByTagName('reset')[0]?.namespaceURI).toBe(null); @@ -336,7 +336,7 @@ describe('parseXmlDocument', () => { it('returns an error if non-whitespace character data follows the document element', () => { const xml = `text`; expect(() => slimdom.parseXmlDocument(xml)).toThrowErrorMatchingInlineSnapshot( - `"document must not contain text outside of elements"` + `"document must not contain text outside of elements"`, ); }); @@ -422,9 +422,13 @@ describe('parseXmlDocument', () => { it('returns an error for entities that expand to content that is not well-formed', () => { const xml = `text">]>&wrong;`; - expect(() => slimdom.parseXmlDocument(xml)).toThrowErrorMatchingInlineSnapshot( - `"replacement text for entity "wrong" is not well-formed - element "p" is missing a closing tag"` - ); + expect(() => slimdom.parseXmlDocument(xml)).toThrowErrorMatchingInlineSnapshot(` + "replacement text for entity "wrong" is not well-formed - element "p" is missing a closing tag + At line 1, character 2: + +

text + ^" + `); }); it('returns an error for entity references in element tags', () => { @@ -672,9 +676,13 @@ describe('parseXmlDocument', () => { it('returns an error if there are not enough end tags', () => { const xml = ''; - expect(() => slimdom.parseXmlDocument(xml)).toThrowErrorMatchingInlineSnapshot( - `"document is not well-formed - element "root" is missing a closing tag"` - ); + expect(() => slimdom.parseXmlDocument(xml)).toThrowErrorMatchingInlineSnapshot(` + "document is not well-formed - element "root" is missing a closing tag + At line 1, character 2: + + + ^^^^" + `); }); it('returns an error if there are too many end tags', () => { diff --git a/test/dom-parsing/parseXmlFragment.tests.ts b/test/dom-parsing/parseXmlFragment.tests.ts index 4ef1889..ccf0ecb 100644 --- a/test/dom-parsing/parseXmlFragment.tests.ts +++ b/test/dom-parsing/parseXmlFragment.tests.ts @@ -66,9 +66,13 @@ describe('parseXmlFragment', () => { it('requires the content to be well-formed', () => { const xml = `content`; - expect(() => slimdom.parseXmlFragment(xml)).toThrowErrorMatchingInlineSnapshot( - `"fragment is not well-formed - element "missing-end-tag" is missing a closing tag"` - ); + expect(() => slimdom.parseXmlFragment(xml)).toThrowErrorMatchingInlineSnapshot(` + "fragment is not well-formed - element "missing-end-tag" is missing a closing tag + At line 1, character 2: + + content + ^^^^^^^^^^^^^^^" + `); }); it('works with fragments starting with a PI that looks like the XML declaration', () => {