Repository navigation
Conversation
…aration A comment or directive seen while p.prev was still the document node was added with AddSibling(p.prev, ...), which makes it a sibling of the document node itself, so it was dropped from the tree. A processing instruction in the same position already becomes a child of the document; do the same for comments and directives.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a document has no XML declaration, a comment or DOCTYPE that comes before the root element is dropped from the parsed tree:
With a declaration first (
<?xml version="1.0"?><!-- license --><!DOCTYPE r><r/>) both nodes are kept, and a processing instruction in the same position (<?pi?><r/>) is kept as well.In
parser.parse, thexml.Commentandxml.Directivecases attach the node relative top.prev. Before anything else has been seen,p.previs the document node andp.level == p.prev.level == 0, so the node is added withAddSibling(p.prev, node): it becomes a sibling of the document node and is unreachable from it. Thexml.ProcInstcase already handles this position by making the node a child of the document at level 1.I noticed it while comparing xmlquery's
OutputXMLagainst libxml2's canonical form on generated documents; documents that started with a comment or a DOCTYPE and had no declaration lost those nodes.The comment and directive cases now do what the processing-instruction case does when
p.previs the document node: add the node as a child of the document at level 1 and make itp.prev. The following root element is then attached as its sibling, as it is after a leading processing instruction today, so no synthetic<?xml version="1.0"?>is inserted in front of it (the same as for<?pi?><r/>onmaster).Documents with a declaration, or with nothing before the root element, are unaffected:
TestMissDeclarationstill gets the synthetic declaration,TestDirectiveandTestMultipleProcInstare unchanged.TestLeadingCommentAndDoctypeWithoutDeclarationchecks the document children,OutputXML,//comment()and that the root's own comment child is untouched;TestLeadingCommentWithWhitespacecovers a CRLF between the comment and the root. Both fail onmasterand pass here;go test ./...andgo vet ./...are clean.