fix(usvg): accept leading whitespace before the XML declaration#1076
Open
StefanoD wants to merge 1 commit into
Open
fix(usvg): accept leading whitespace before the XML declaration#1076StefanoD wants to merge 1 commit into
StefanoD wants to merge 1 commit into
Conversation
`Tree::from_str` (and thus `from_data`) rejected an otherwise valid SVG whenever any whitespace preceded the `<?xml ?>` declaration — e.g. a string literal that starts on its own line, or a pretty-printed file with a leading blank line. An XML declaration is only valid at the very start of the document, so the underlying parser reported "unexpected XML declaration". Trim leading whitespace before handing the text to `roxmltree`. The same input compressed onto a single line, or loaded via `include_bytes!` from a file beginning with `<?xml`, already worked; this makes the formatted variant behave identically. gzip-compressed input benefits too, as it is routed through `from_str` after decompression. Adds regression tests for both the plain and gzip-compressed cases. Closes linebender#1057 Reported downstream as iced-rs/iced#3357. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Tree::from_str(and thusfrom_data) rejected an otherwise valid SVG whenever any whitespace preceded the<?xml ?>declaration — e.g. a string literal that starts on its own line, or a pretty-printed file with a leading blank line. An XML declaration is only valid at the very start of the document, so the underlying parser reported "unexpected XML declaration".Trim leading whitespace before handing the text to
roxmltree. The same input compressed onto a single line, or loaded viainclude_bytes!from a file beginning with<?xml, already worked; this makes the formatted variant behave identically. gzip-compressed input benefits too, as it is routed throughfrom_strafter decompression.Adds regression tests for both the plain and gzip-compressed cases.
Closes #1057
Reported downstream as iced-rs/iced#3357.
Generated by Claude.
Note: I accidentally closed the original PR (#1058) by deleting my fork, which auto-closed it. This reopens the same change — the branch and commits are unchanged.