You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
XML doctype system IDs can serialize as invalid XMLÂ #2571
I bumped into this odd edge case while importing some old technical documentation.
XML system literals in a doctype can use either single or double quotes as their delimiter.
jsoup accepts the valid XML below, but DocumentType currently always serializes the system identifier using double quotes:
Stringxml = "<!DOCTYPE root SYSTEM 'a\"b.dtd'><root />";
Documentdoc = Jsoup.parse(xml, "", Parser.xmlParser());
System.out.println(doc.outerHtml());
// <!DOCTYPE root SYSTEM "a"b.dtd"><root />
Escaping the quote as " doesn't work because entity references are not interpreted inside a system literal; it would change the identifierâs value. Converting it to %22 would also change the stored identifier, and the XML external-identifier specification says URI escaping should happen only when necessary and as late as possible during dereferencing.
The fix will be to continue using double quotes normally, but use single quotes when the system identifier contains a double quote.
Activity
Fix XML doctype system ID quote serialization