Case-insensitive XML declaration detection per XML spec section 2.6

Open
#927 2 comments 2 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
34/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
rust
Domain
backend

Research direction

Start by reading the parser logic that classifies processing instruction targets and the related tests; the issue does not name specific files. Compare the existing lowercase xml declaration behavior with mixed-case targets and unterminated inputs from the table. Done means the parser exposes behavior that lets callers handle reserved case variants while preserving later parse errors and regular processing instructions.

Written by the indexing model from the issue text.

Description

According to https://www.w3.org/TR/xml/#sec-pi:

The target names "XML", "xml", and so on are reserved for standardization in this or future versions of this specification.

This means PITarget names matching [Xx][Mm][Ll] (any case variant) are reserved and shouldn't be considered valid processing instructions.
Currently, quick-xml treats only lowercase <?xml as an XML declaration, while other case variants are treated as regular processing instructions.

The above is basically a standalone issue and probably should be addressed somehow. This is related to Ruffle and ideally should be solved in such a way that allows Ruffle to properly replicate Flash behaviour.

Here is a table laying out what is currently ok and what isn't:

Input quick-xml Event/Error Flash Player behavior Note
<?xml version='1.0'?>\<r/\> Event::Decl XML declaration ✓ Ok
<?XML version='1.0'?>\<r/\> Event::PI XML declaration ✓ Workaround possible: we can check Event::PI and treat it as an xml declaration
<?XmL version='1.0'?>\<r/\> Event::PI XML declaration ✓ Workaround possible: we can check Event::PI and treat it as an xml declaration
<?xml version='1.0'? (unterminated) UnclosedXmlDecl Error #1092 (unterminated XML declaration) ✓ Ok
<?XML version='1.0'? (unterminated) UnclosedPI Error #1092 (unterminated XML declaration) ✗ PI target not exposed in error, cannot distinguish from regular PI
<?XmL version='1.0'? (unterminated) UnclosedPI Error #1092 (unterminated XML declaration) ✗ PI target not exposed in error, cannot distinguish from regular PI
<?test foo?\> Event::PI Processing instruction ✓ Ok
<?test foo? (unterminated) UnclosedPI Error #1097 (unterminated processing instruction) ✓ Ok

If an error was raised as soon as the parser encounters something like <?XmL, then parsing stops and Ruffle would have no chance to process the rest of the xml and for example raise an error about an unterminated xml declaration or any other error that would be encountered later.

One possible solution would be to treat all [Xx][Mm][Ll] case variants as XML declarations, since the spec reserves these names anyway.

Alternatively, new event/error types could be added (e.g., Event::ReservedPI / SyntaxError::UnclosedReservedPI) to let users decide how to handle them. However, this might be more complexity than needed.

Dominant language
Rust
Stars
1.6k
Forks
299
Avg merge
2d 4h
Merged PRs (30d)
9

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from tafia/quick-xml

All issues in tafia/quick-xml

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.