Skip to content

fix(expand): split embedded @-slice like GNU @-lists - #1032

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/1011-embedded-atsplit
Oct 22, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/1011-embedded-atsplit

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Closes #1011. GNU splits embedded @-slices via flag-driven double expansion (subst.c:10119 chk_atstar -> parameter_brace_substring array_subrange keeping @-list boundaries); the raw-word segment scanner only admitted exact "${name[@]}" shapes, so [@]:off fell into the joining String path. Fix: ArrayAtSlice/PositionalAtSlice segment shapes (brace-aware span check) reusing the standalone helpers; [*] slices, ! indirects, :-/:=/:+/ :? operators, and $(...) offsets all fall through unchanged. Tests: lib 693 + 9 new regression + array/reference suites green, executor_tests delta-free vs baseline; GNU parity (issue repro + extended matrix incl. empty/negative/out-of-range/IFS variants) byte-identical, all deltas wrong->right.

GNU anchor: subst.c:9050 parameter_brace_substring (VT_ARRAYVAR /
VT_POSPARMS arms, subst.c:9101-9136) keeps the @-list word boundaries
(array_subrange / string_list_pos_params), and subst.c:10119-10128
parameter_brace_expand calls chk_atstar (subst.c:7635-7639) before the
operator switch, so a quoted [@]/@ marks quoted_dollar_at even with the
":" substring operator. The enclosing word therefore splits with affixes
on the first/last element: f "A|${a[@]:1:2}|B" is argc=2 ([A|y] [z|B]).

Root cause: the raw-word segment scanner quoted_positional_at_segments
only admitted the exact "${name[@]}" / ${name[@]} / ${@} spans as
word-list sources, so an @-slice span fell through to the joining
String path (argc=1). Standalone slices already fanned out via
array_at_word_values / quoted_positional_at_word_values.

Fix (whitelist, rubash#117 discipline): admit name[@]:off[:len] and
@:off[:len] spans in the quoted-body and unquoted top-level scanner
arms, resolving them with the same slicing helpers as the standalone
paths (array_subscript_range_values,
positional_parameter_substring_with_zero). Declined shapes stay on the
pre-existing path byte-for-byte: [*] slices (GNU joins them),
!-indirect forms, operator-looking rests (:- := :+ :?), and
command-substitution offsets ($(/backtick need the &mut evaluator).

Verified: issue repro + IFS/empty-element/for-list matrix byte-identical
to bash 5.3.20 via script files; 9 new regression tests, lib (693) and
related suites green; executor_tests failure set identical to baseline
(13 pre-existing Termux-env failures). Known gaps left for follow-ups:
embedded ${!a[@]} keys, :-alternates holding slices, comsub offsets.
@caomengxuan666 caomengxuan666 changed the title fix(expand): split embedded "" like GNU @-lists fix(expand): split embedded @-slice like GNU @-lists Oct 22, 2026
@caomengxuan666
caomengxuan666 merged commit 6d2ab62 into master Oct 22, 2026
8 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/1011-embedded-atsplit branch October 23, 2026 04:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Embedded ${a[@]:offset} does not word-split like GNU (joins instead of splitting)

1 participant