Repository navigation
fix(expand): split embedded @-slice like GNU @-lists - #1032
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.