Skip to content

[bug] inside guard reports SET for unset element; empty quoted element dropped in unquoted slice assignment c=( ${b[@]+"${b[@]:0:2}"} ) — liquidprompt test_array 2/3 fail #315

Closed

Description

@caomengxuan666

Summary

Two array-expansion divergences found by the ecosweep2 lane running liquidprompt's own shunit2 suite (tests/test_array.sh, 2 of 3 tests fail). Both live in the ${arr[@]+"…"}-guarded expansion family (residuals next to the closed #147 / #295 area):

1) ${a[2]+x} inside an ${a[@]+…} guard reports SET for an UNSET element.

typeset -a a
a[1]=1
[[ -n ${a[@]+"${a[2]+x}"} ]] && echo NONEMPTY || echo EMPTY
  • GNU 5.3.0: EMPTY (element 2 is unset, +x yields nothing) — rubash @116b12aa: NONEMPTY.
    This breaks the standard is-element-set idiom (test_array.sh:110: assertFalse '[[ -n ${array_a[@]+"${array_a[1]+x}"} ]]'-class assertions).

2) Empty element is dropped in an unquoted quoted-slice array assignment.

b=( "" foobar )
c=( ${b[@]+"${b[@]:0:2}"} )
echo "${#c[@]}"; IFS=/; echo "[${c[*]}]"
  • GNU: 2 and [/foobar] (elements "" and foobar survive; join with / gives leading separator) — rubash: 1 and [foobar] (the empty quoted element vanishes).
    (test_array.sh:81-83 "concat empty string alt expected: but was:".)

GNU C source anchors (vendored third_party/bash)

  • subst.c:10348 case '+': in parameter_brace_expand() — the + alternate is produced only when the parameter (here: the subscripted element, via parameter_brace_expand_word subst.c:7663 call sites 7861/7955) is bound; an unset subscripted element yields no alternate.
  • Empty-element retention through the unquoted slice: subst.c:11229 expand_word_internal() — quoted elements of ${arr[@]:X:Y} expand with quoting flags that keep empty words until field splitting (subst.c:13219 expand_word_list_internal()); GNU keeps the empty field.

Reproducer

Script p-lparr.sh (both shells, script-file): rubash t1=NONEMPTY(bug) t2 count=1 t3 join=[foobar], GNU t1=EMPTY t2 count=2 t3 join=[/foobar]; rc 0/0.

Environment / artifacts

  • rubash release @116b12aa (wt13/ecosweep2); oracle WSL GNU bash 5.3.0
  • liquidprompt @afd7e83 suite outputs target/issue-suites/results/ecosweep2/lp/rb/test_array.sh.*; probes p-lparr.sh + rb-lparr.out/gnu-lparr.out

Activity

  1. added
    bug
    on Sep 29, 2026
  2. added 3 commits that reference this issue on Sep 29, 2026
  3. caomengxuan666 commented on Sep 29, 2026

    @caomengxuan666
    MemberAuthor

    Fixed by wt13/sweepfix (faf83863, master 203c2b5): three consumers each lost word-list semantics - [[ ]] operands treated the QUOTED_NULL marker (U+E002, CTLNUL port) as a visible byte ([[ -n ]] true); the argv/for multiword check only recognized a literal [@]} tail so slices missed it and merged through the String path losing empties; the compound-assignment path had no word-list branch. All three fixed against subst.c:10348 (+ case), :7993/:8023-8027 (expand_string_for_rhs -> l->next /*qdollaratp), :8036-8044/:11940-11944 (QUOTED_NULL/W_HASQUOTEDNULL), cond.c cond_expand_word. 19-shape matrix byte-identical; liquidprompt test_array rc=1(failures=3) -> rc=0. One recorded residual ([[ ${b[@]+"${b[@]:0:2}"} == ... ]] conditional single-word join drops a leading empty - assignment context correct).

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