Skip to content

v5.2.1 broke parsing doctypes with DTDs #747

@emmercm

Description

@emmercm
  • Are you running the latest version?
  • Have you included sample input, output, error, and expected output?
  • Have you checked if you are using correct configuration?
  • Did you try online tool?
  • Have you checked the docs for helpful APIs and examples?

Description

v5.2.1 started throwing exceptions when parsing doctypes with DTDs. Example stack trace:

Error: Expected '(', found "E"
    at readElementExp (<redacted>/igir/node_modules/fast-xml-parser/src/xmlparser/DocTypeReader.js:213:15)
    at readDocType (<redacted>/igir/node_modules/fast-xml-parser/src/xmlparser/DocTypeReader.js:32:37)
    at OrderedObjParser.parseXml (<redacted>/igir/node_modules/fast-xml-parser/src/xmlparser/OrderedObjParser.js:265:24)
    at XMLParser.parse (<redacted>/igir/node_modules/fast-xml-parser/src/xmlparser/XMLParser.js:36:48)
    at Function.fromXmlString (<redacted>/igir/src/types/dats/datObject.ts:26:8)
    at DATScanner.parseXmlDat (<redacted>/igir/src/modules/dats/datScanner.ts:281:29)
    at DATScanner.parseDatContents (<redacted>/igir/src/modules/dats/datScanner.ts:255:25)
    at <redacted>/igir/src/modules/dats/datScanner.ts:163:19
    at processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async Function.createStreamFromFile (<redacted>/igir/src/types/files/file.ts:395:14)
    at async DATScanner.parseDatFile (<redacted>/igir/src/modules/dats/datScanner.ts:161:13)
    at async <redacted>/igir/src/modules/dats/datScanner.ts:131:17

Input

Example XML:

<?xml version="1.0"?>
<!DOCTYPE softwarelists [
<!ELEMENT softwarelists (softwarelist*)>
	<!ELEMENT softwarelist (notes?, software+)>
		<!ATTLIST softwarelist name CDATA #REQUIRED>
		<!ATTLIST softwarelist description CDATA #IMPLIED>
		<!ELEMENT notes (#PCDATA)>
		<!ELEMENT software (description, year, publisher, notes?, info*, sharedfeat*, part*)>
			<!ATTLIST software name CDATA #REQUIRED>
			<!ATTLIST software cloneof CDATA #IMPLIED>
			<!ATTLIST software supported (yes|partial|no) "yes">
			<!ELEMENT description (#PCDATA)>
			<!ELEMENT year (#PCDATA)>
			<!ELEMENT publisher (#PCDATA)>
			<!ELEMENT notes (#PCDATA)>
			<!ELEMENT info EMPTY>
				<!ATTLIST info name CDATA #REQUIRED>
				<!ATTLIST info value CDATA #IMPLIED>
			<!ELEMENT sharedfeat EMPTY>
				<!ATTLIST sharedfeat name CDATA #REQUIRED>
				<!ATTLIST sharedfeat value CDATA #IMPLIED>
			<!ELEMENT part (feature*, dataarea*, diskarea*, dipswitch*)>
				<!ATTLIST part name CDATA #REQUIRED>
				<!ATTLIST part interface CDATA #REQUIRED>
				<!ELEMENT feature EMPTY>
					<!ATTLIST feature name CDATA #REQUIRED>
					<!ATTLIST feature value CDATA #IMPLIED>
				<!ELEMENT dataarea (rom*)>
					<!ATTLIST dataarea name CDATA #REQUIRED>
					<!ATTLIST dataarea size CDATA #REQUIRED>
					<!ATTLIST dataarea databits (8|16|32|64) "8">
					<!ATTLIST dataarea endian (big|little) "little">
					<!ELEMENT rom EMPTY>
						<!ATTLIST rom name CDATA #IMPLIED>
						<!ATTLIST rom size CDATA #IMPLIED>
						<!ATTLIST rom length CDATA #IMPLIED>
						<!ATTLIST rom crc CDATA #IMPLIED>
						<!ATTLIST rom sha1 CDATA #IMPLIED>
						<!ATTLIST rom offset CDATA #IMPLIED>
						<!ATTLIST rom value CDATA #IMPLIED>
						<!ATTLIST rom status (baddump|nodump|good) "good">
						<!ATTLIST rom loadflag (load16_byte|load16_word|load16_word_swap|load32_byte|load32_word|load32_word_swap|load32_dword|load64_word|load64_word_swap|reload|fill|continue|reload_plain) #IMPLIED>
				<!ELEMENT diskarea (disk*)>
					<!ATTLIST diskarea name CDATA #REQUIRED>
					<!ELEMENT disk EMPTY>
						<!ATTLIST disk name CDATA #REQUIRED>
						<!ATTLIST disk sha1 CDATA #IMPLIED>
						<!ATTLIST disk status (baddump|nodump|good) "good">
						<!ATTLIST disk writeable (yes|no) "no">
				<!ELEMENT dipswitch (dipvalue*)>
					<!ATTLIST dipswitch name CDATA #REQUIRED>
					<!ATTLIST dipswitch tag CDATA #REQUIRED>
					<!ATTLIST dipswitch mask CDATA #REQUIRED>
					<!ELEMENT dipvalue EMPTY>
						<!ATTLIST dipvalue name CDATA #REQUIRED>
						<!ATTLIST dipvalue value CDATA #REQUIRED>
						<!ATTLIST dipvalue default (yes|no) "no">
]>

<softwarelists>
	<softwarelist name="snes" description="Nintendo SNES cartridges">
		<software name="aokidenp" cloneof="aokiden">
			<description>Aoki Densetsu Shoot! (Japan, prototype)</description>
			<year>1994</year>
			<publisher>KSS</publisher>
			<info name="alt_title" value="蒼き伝説シュート!"/>
			<part name="cart" interface="snes_cart">
				<feature name="battery" value="BATT CR2032" />
				<feature name="cart_model" value="no shell" />
				<feature name="lockout" value="" />
				<feature name="pcb" value="SHVC-4PV5B-01" />
				<feature name="slot" value="lorom" />
				<feature name="u1" value="U1 EPROM" />
				<feature name="u2" value="U2 EPROM" />
				<feature name="u3" value="U3 EPROM" />
				<feature name="u4" value="U4 EPROM" />
				<feature name="u5" value="U5 SRAM" />
				<feature name="u6" value="U6 PLD" />
				<feature name="u7" value="U7 74LS157" />
				<feature name="u8" value="U8 CIC" />
				<dataarea name="rom" size="1572864">
					<rom name="shoot 1 kss.u1" size="524288" crc="71306e06" sha1="253ec028d68a85209dc3e5846a2a2f5b582fed7b"/>
					<rom name="shoot 2 kss.u2" size="524288" crc="d07e1be3" sha1="7a58acb027ca15c1054e58f43156c2d99f62d16c"/>
					<rom name="shoot 3 kss.u3" size="524288" crc="380ed94f" sha1="8607ce31748ae73b9aa7aacda80c843622c61a79"/>
				</dataarea>
				<dataarea name="nvram" size="131072">
				</dataarea>
			</part>
		</software>
	</softwarelist>
</softwarelists>

Code

const xmlContents = '<example below>';
const obj = new XMLParser({
  ignoreAttributes: false,
  attributeNamePrefix: '',
}).parse(xmlContents)

Output

See the example stack trace above.

expected data

See the example input above.

Would you like to work on this issue?

  • Yes
  • No

Bookmark this repository for further updates. Visit SoloThought to know about recent features.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions