You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Case-insensitive XML declaration detection per XML spec section 2.6 #927
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.
Yes, I'm aware of this issue. The planned way to fix it it is create a validation layer. Very WIP of how this API may look can be found in my validation branch.
However, according to the XML spec, only lowercased <?xml must be threated as XML declaration (that still means that <?XML is reserved according to the rules that you correctly highlighted). This is also indirectly implied by the recommended encoding guessing algorithm, which takes into account only lowercased letters.
Is it important for Flash to have slightly different processing of such syntaxially invalid XMLs (as you noted, you may process <?XML as regular processing instruction, quick-xml never has plans to totally forbid processing of the reserved XML names, it will leave it to the user's wishes).
Actually, you may known distinguish between unclosed Flash XML declaration and processing instructions. .error_position() will point at < of the unclosed <XML, so you may inspect bytes at that location if they looks like Flash declaration.
.error_position() is a global counter, so you need to save .buffer_position() before reading the event, so you may get the local offset in the buffer to which you read data:
let r_start = reader.buffer_position();let b_start = buf.len();match reader.read_event_into(buf){Err(...) => {let s = b_start + (reader.error_position() - r_start)asusize;if buf[s..s + 5].eq_ignore_ascii_case("<?xml"){// Looks like Flash XML declaration}}}
Activity
Mingun commentedon Dec 26, 2025
Yes, I'm aware of this issue. The planned way to fix it it is create a validation layer. Very WIP of how this API may look can be found in my validation branch.
However, according to the XML spec, only lowercased
<?xmlmust be threated as XML declaration (that still means that<?XMLis reserved according to the rules that you correctly highlighted). This is also indirectly implied by the recommended encoding guessing algorithm, which takes into account only lowercased letters.Is it important for Flash to have slightly different processing of such syntaxially invalid XMLs (as you noted, you may process
<?XMLas regular processing instruction, quick-xml never has plans to totally forbid processing of the reserved XML names, it will leave it to the user's wishes).Mingun commentedon Dec 27, 2025
Actually, you may known distinguish between unclosed Flash XML declaration and processing instructions.
.error_position()will point at<of the unclosed<XML, so you may inspect bytes at that location if they looks like Flash declaration..error_position()is a global counter, so you need to save.buffer_position()before reading the event, so you may get the local offset in the buffer to which you read data: