Skip to content

XER emits wrong CHOICE item name for SEQUENCE OF CHOICE #561

Description

@k1ll3rb1z

Hi,
I may have found a bug when decoding uper to xer, where choice item name is wrong.
A small patch is proposed as well.

Versions

  • rasn: 0.28.13
  • OS: Linux
  • Rust: stable

Steps to Reproduce

  1. Clone/run this minimal repro crate: rasn-xer-choice-repro
  2. Run:
cd rasn-xer-choice-repro
cargo run

Actual Behavior

Output contains:

<Msg><messageData><elementIds><constrainedData><clearanceType><approach /></clearanceType><assignedTime /></constrainedData></elementIds></messageData></Msg>

The child of elementIds is emitted as constrainedData.

Expected Behavior

Output should contain:

<Msg><messageData><elementIds><uM270><clearanceType><approach /></clearanceType><assignedTime /></uM270></elementIds></messageData></Msg>

The child of elementIds should be the CHOICE alternative name uM270.

Why this looks like an encoder label bug

  • Semantic decode/encode is consistent at UPER level (same payload round-trips).
  • The mismatch is in XER element naming for CHOICE items inside SEQUENCE OF.

Suspected Area

Likely interaction in src/xer/enc.rs among:

  • encode_sequence_of
  • encode_choice
  • field_tag_stack
  • entering_list_item_type

Hypothesis: list-item CHOICE encoding can fall back to a parent/sibling identifier from field_tag_stack (constrainedData) instead of using the CHOICE variant identifier (uM270).

Suggested Fix Direction

  1. Preserve CHOICE variant identifier context for list-item CHOICE emission.
  2. Avoid parent stack fallback when encoding list-item CHOICE variants.
  3. Add a regression test for SEQUENCE OF CHOICE with sibling optional fields.

Proposed patch

https://github.com/k1ll3rb1z/rasn-xer-choice-repro/blob/main/rasn_encode_choice_list_item_fix.patch

Attached Repro

Thanks

Note: AI was used to find a patch for my project

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions