Skip to content

Fix duplicated <?xml-stylesheet?> processing instruction in XML output#1895

Open
Synvoya wants to merge 1 commit into
httpie:masterfrom
Synvoya:fix/xml-stylesheet-pi-duplicated
Open

Fix duplicated <?xml-stylesheet?> processing instruction in XML output#1895
Synvoya wants to merge 1 commit into
httpie:masterfrom
Synvoya:fix/xml-stylesheet-pi-duplicated

Conversation

@Synvoya

@Synvoya Synvoya commented Jul 11, 2026

Copy link
Copy Markdown

Description

The XML formatter duplicated a leading <?xml-stylesheet?> (or <?xml-model?>) processing instruction in prettified output.

parse_declaration accepted any body starting with <?xml, so a PI whose target merely begins with xml — the two W3C-standard ones, xml-stylesheet and xml-model — was misidentified as the XML declaration. pretty_xml then dropped toprettyxml's generated declaration and re-inserted that "declaration" (the PI), which toprettyxml had already preserved once, so the instruction appears twice.

Fix

Require the declaration target to be exactly xml (the character after <?xml must be whitespace or ?), so a <?xml-...?> processing instruction is no longer misdetected.

Test

Added test_xml_leading_processing_instruction_not_duplicated (parametrized over xml-stylesheet / xml-model). All existing tests/test_xml.py pass; reverting only the fix fails the new test.

parse_declaration matched any body starting with "<?xml", so a processing
instruction whose target merely begins with "xml" (the W3C-standard
<?xml-stylesheet?> and <?xml-model?>) was misdetected as the XML declaration.
pretty_xml then re-inserted it after toprettyxml had already preserved it,
duplicating the instruction. Require the declaration target to be exactly "xml".
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.

1 participant