Skip to content

[Rust & Direct Codecs] Enforce xsi:nil handling in Rust streaming codecs and strict xs:decimal / XML well-formedness checks in direct codecs #169

Open

Description

@nth-bailey

Summary

Audit of recent nillable, scalar-parsing, and XML parser hardening PRs identified three related codec correctness gaps in generated code:

  1. Rust xsi:nil missing on nillable="true" nested fields (crates/polyxml-core/src/codegen/rust/mod.rs): While decode_xml / encode_xml for simple/flat fields checks Option, Rust streaming codecs do not check xsi:nil="true" / "1" on nillable="true" child elements before delegating to nested T::decode_xml / T::decode_xml_empty. If AttrOnly has a required attribute id, <item xsi:nil="true"/> fails with Missing required attribute 'id'. Conversely, encode_xml omits minOccurs="1" nillable="true" elements when None instead of writing <item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/> (unlike C++20 and Java direct-codec).
  2. Permissive xs:decimal exponent notation (eclipse-ee4j/jaxb-ri#2053): Per W3C XSD Part 2 §3.2.3.1, the lexical space of xs:decimal is [+-]?[0-9]+(\.[0-9]+)? (and .123 / 123.), and MUST NOT contain exponent notation (1e5, 1.5E-2). Currently Java direct-codec (new java.math.BigDecimal(raw)), Rust/Go f64, C++20 parse_float<double>, and TypeScript parseFloatValue all accept 1e5 as a valid xs:decimal.
  3. Self-contained C++20 & TypeScript direct-codec XML well-formedness (NaturalIntelligence/fast-xml-parser#909, #913, #915, #916, tafia/quick-xml#1044): Our zero-dependency recursive-descent parsers in crates/polyxml-core/src/codegen/cpp/codec.rs and crates/polyxml-core/src/codegen/typescript/codec.rs currently allow:
    • -- inside XML comments (<!-- a -- b -->)
    • raw ]]> in element character data
    • duplicate attributes on the same start tag (silently overwriting in TS)
    • raw < or unknown/unterminated & entities inside attribute values or character data
    • arbitrary trailing non-whitespace/non-misc garbage after the closing root tag (<Root/>trailing_junk) because parse_xml_document returns immediately after parsing the root element without trailing skip_misc + EOF verification.

Upstream references: tefra/xsdata#1233 (tefra/xsdata#1233), tefra/xsdata#1234 (tefra/xsdata#1234), tefra/xsdata#1244 (tefra/xsdata#1244), eclipse-ee4j/jaxb-ri#2053 (eclipse-ee4j/jaxb-ri#2053), NaturalIntelligence/fast-xml-parser#909 (NaturalIntelligence/fast-xml-parser#909), NaturalIntelligence/fast-xml-parser#913 (NaturalIntelligence/fast-xml-parser#913), NaturalIntelligence/fast-xml-parser#915 (NaturalIntelligence/fast-xml-parser#915), NaturalIntelligence/fast-xml-parser#916 (NaturalIntelligence/fast-xml-parser#916), and tafia/quick-xml#1044 (tafia/quick-xml#1044).

Minimal Reproducers

  • Nillable attributes-only complexType: tests/fixtures/conformance/wave9/nil_attr_only.xsd
  • Strict xs:decimal lexical space: tests/fixtures/conformance/wave9/decimal_strict.xsd

Expected Behavior

  1. Rust streaming codecs inspect xsi:nil ("true" / "1") on nillable="true" child elements (mapping to None and skipping child element events) and emit xsi:nil="true" when minOccurs >= 1 && nillable && value.is_none().
  2. xs:decimal parsers in generated codecs reject e/E exponent notation per W3C XSD Part 2 §3.2.3.1.
  3. C++20 and TypeScript parse_xml_document / parseXmlDocument enforce trailing misc-only EOF checks, reject -- inside comments, reject raw ]]> in text, reject duplicate attribute names, and reject unescaped < or unknown/unterminated &... in text/attributes.

Activity

  1. added
    bug
    codegen
    target:rust
    target:cpp
    target:java
    target:typescript
    on Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcodegentarget:cpptarget:javatarget:rusttarget:typescript

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions