Skip to content

fix(usvg): accept leading whitespace before the XML declaration#1076

Open
StefanoD wants to merge 1 commit into
linebender:mainfrom
StefanoD:fix/svg-leading-whitespace-xml-declaration
Open

fix(usvg): accept leading whitespace before the XML declaration#1076
StefanoD wants to merge 1 commit into
linebender:mainfrom
StefanoD:fix/svg-leading-whitespace-xml-declaration

Conversation

@StefanoD

Copy link
Copy Markdown

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 #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.

`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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

usvg fails to parse valid SVG when whitespace precedes the <?xml ?> declaration

1 participant