Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid DOCTYPE when parsing svg file #546

Closed
2 tasks
gartcimore opened this issue Feb 20, 2023 · 7 comments
Closed
2 tasks

Invalid DOCTYPE when parsing svg file #546

gartcimore opened this issue Feb 20, 2023 · 7 comments
Labels

Comments

@gartcimore
Copy link

  • [x ] Are you running the latest version?
  • [ x] Have you included sample input, output, error, and expected output?
  • Have you checked if you are using correct configuration?
  • [ x] Did you try online tool?

Description

Library is-svg was using version 3.19.0. When upgrading to 4.1.2, some test cases are not successful anymore when parsing valid xml input samples
Branch with the change can be found here

Input

test cases from is-svg library is using this svg file
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [ <!ENTITY Smile " <rect x='.5' y='.5' width='29' height='39' fill='black' stroke='red'/> <g transform='translate(0, 5)'> <circle cx='15' cy='15' r='10' fill='yellow'/><circle cx='12' cy='12' r='1.5' fill='black'/><circle cx='17' cy='12' r='1.5' fill='black'/><path d='M 10 19 L 15 23 20 19' stroke='black' stroke-width='2'/></g>"> ]><svg width="850px" height="700px" version="1.1" xmlns="http://www.w3.org/2000/svg"><g transform="matrix(16,0,0,16,0,0)">&Smile;</g></svg>

Code

input = input.toString().trim();

if (XMLValidator.validate(input) !== true) {
		return false;
	}

	let jsonObject;
	const parser = new XMLParser();

	try {
		jsonObject = parser.parse(input);
	} catch (_) {
		return false;
	}

	if (!jsonObject) {
		return false;
	}

	if (!('svg' in jsonObject)) {
		return false;
	}

Output

Error: Invalid DOCTYPE
at readDocType (/Users/larustue/depots/is-svg/node_modules/fast-xml-parser/src/xmlparser/DocTypeReader.js:73:27)
at OrderedObjParser.parseXml (/Users/larustue/depots/is-svg/node_modules/fast-xml-parser/src/xmlparser/OrderedObjParser.js:246:24)
at XMLParser.parse (/Users/larustue/depots/is-svg/node_modules/fast-xml-parser/src/xmlparser/XMLParser.js:35:48)
at isSvg (/Users/larustue/depots/is-svg/index.js:24:23)
at /Users/larustue/depots/is-svg/test.js:66:14
at Test.callFn (/Users/larustue/depots/is-svg/node_modules/ava/lib/test.js:364:21)
at Test.run (/Users/larustue/depots/is-svg/node_modules/ava/lib/test.js:377:23)
at Runner.runSingle (/Users/larustue/depots/is-svg/node_modules/ava/lib/runner.js:259:19)
at /Users/larustue/depots/is-svg/node_modules/ava/lib/runner.js:322:16
at processTicksAndRejections (node:internal/process/task_queues:95:5)

expected data

I guess it should not failed because the XML is valid and doctype used to be correct, there seems to be backward compatibility broken somewhere

Would you like to work on this issue?

  • Yes
  • [ x] No

Bookmark this repository for further updates.

@github-actions
Copy link

I'm glad you find this repository helpful. I'll try to address your issue ASAP. You can watch the repo for new changes or star it.

@amitguptagwl
Copy link
Member

So many things were changed in version 3 and 4. Please check Changelog

@gartcimore
Copy link
Author

I checked the changelog, nothing can be found about xml being invalid with entities in doctype. Is the provided example a valid xml in your opinion ? Should it trigger the exception of invalid doctype ?

@amitguptagwl
Copy link
Member

After 4.0.0-beta.3 DOCTYPE are supported but with very limited features. You may probably want to set processEntities: false with XML parser.

@gartcimore
Copy link
Author

I tried already with this option set, the behavior was the same, an error was still triggered

@amitguptagwl
Copy link
Member

Have you tried with new version recently published?

@gartcimore
Copy link
Author

I used the latest version 4.1.3 published, now everything is working perfectly, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants