Skip to content

Initial compound array assignment loses backslashes in single-quoted elements (A=([0]='\[\e[33m\]Z') stores [e[33m]Z) #288

Closed

Description

@caomengxuan666

Symptom

oh-my-bash agnoster's prompt shows literal [e[33m] noise: the theme stores prompt segments in an array (symbols+=($REPLY'⚡') with $REPLY=\[\e[33m\]), and the stored element has lost every backslash.

Byte-level probe (WSL GNU Bash 5.3.0 as oracle)

A=([0]='\[\e[33m\]Z')
printf '%s' "${A[0]}" | od -c
declare -a D=([0]='\[\e[33m\]Z')
printf '%s' "${D[0]}" | od -c
A+=('\[\e[44m\]W')
printf '%s' "${A[1]}" | od -c

GNU (all three): \ [ \ e [ 3 3 m \ ] Z (backslashes preserved)
rubash before 847ab88: all three [ e [ ... m ] Z (eaten)
rubash after 847ab88: the += arm is fixed; the initial A=([0]=...) and declare -a D=([0]=...) still eat backslashes.

Evidence on the remaining pipeline break

Instrumenting unquote_storage_value (builtins/declare/storage/words.rs) shows the initial-assignment path arrives with the value already in serialized form [0]="\[\e[33m\]Z" — i.e. a quote-removal + re-serialization round trip happened upstream and mishandled the single-quoted interior:

  • expand layer: expand_embedded_parameters_compound (executor/embedded_parameters.rs) runs with preserve_quotes=true and converts ' to the DATA_SQUOTE (\x17, markers.rs:86) carrier; its comment claims "unquote_storage_value decodes it" (embedded_parameters.rs:118).
  • storage layer: grep DATA_SQUOTE src/builtins/declare/storage/ has zero consumers — the decode the comment promises does not exist, and the bare-word arm of unquote_storage_value decodes \x escapes over the carrier-wrapped interior, eating the backslashes.

Secondary observation in the same probe family: $'...' drops the backslash for unknown ANSI-C escapes ($'\]' stores ]; GNU keeps \] — GNU ansic decode keeps the backslash for unrecognized escapes).

Fix direction

Trace the initial compound assignment flow (expand_word.rs expand_plain_assignment_word → expand_embedded_parameters_compound → storage parse/format round trip) and make the single-quoted element interior survive verbatim end to end, exactly like GNU arrayfunc.c assign_compound_array_list's quote removal. The DATA_SQUOTE carrier needs a real consumer (or the flow must stop converting quotes into a carrier nothing decodes). Watch for the agnoster case: elements contain spaces after the colored glyphs, so word-splitting inside the carrier span must stay glued.

Verification bar

  • The probe above byte-identical to GNU (all three arms).
  • tests/regression + cargo test --lib green (array/declare domains are heavily covered: array6.sub, array19.sub, array29.sub, assoc11.sub, assoc15.sub behaviors are pinned by existing tests).
  • Real-console oh-my-bash agnoster shows no literal [e[33m] and correct colors.

Activity

  1. added
    bug
    on Sep 28, 2026
  2. caomengxuan666 commented on Sep 28, 2026

    @caomengxuan666
    MemberAuthor

    Fixed by arrayesc lane (c3ae8b16 + f5f0e861, cherry-picked to master): the compound-array element pipeline ran quote removal TWICE — GNU runs expansion+decode exactly once (arrayfunc.c:557 expand_compound_array_assignment -> subst.c:13219), then stores verbatim (arrayfunc.c:839-842). Four instances fixed: executor A=([0]=...), declare storage, $'...' element emission (parse.y:5564-5571 sh_single_quote re-wrapping), and the arr+=word scalar append (variables.c assign_array_element — single scalar, no IFS split).

    Acceptance (independent verifier): three-arm probe byte-identical to WSL GNU Bash 5.3.0 (od -c, 11 bytes both sides), 14-case assignment x quoting x whitespace matrix green, agnoster real-theme gate PASS (PS1 free of [e[ noise, backslashes intact). 490 lib + 10 new regression + 24/24 regression suite green.

    Two deeper same-family items were honestly declared out of scope by the lane and will be filed separately: Y=($X'⚡') quote-delimiter leak into element data, and declare -a V=([0]=$X'Q') losing backslashes via the non-mut preserve walker.

  3. added a commit that references this issue on Oct 1, 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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions