Repository navigation
fix(expand): unset scalar base has no element 0 for operators - #910
Merged
Merged
Conversation
array_element_parameter_value returned Some("") for index 0 of an
unset variable, so ${Z[0]-d},${Z[0]+a},${Z[0]=d} all misread the
parameter as set-but-empty (only :-, which also treats null as
missing, behaved). Report the reference as unset (None) instead —
the same posture as any other missing element — while a set-but-empty
scalar keeps its empty element 0.
A dynamic scalar (RANDOM/SECONDS/...) reads live through element 0,
shadowing stored seed text: the same dynamic-first precedence plain
$name expansion uses.
Verified against GNU bash 5.3 for -/:-/=/+ on unset, set-empty and
dynamic bases, plus the plain ${Z[0]} empty case. Fixes
cli_tests::c_command_retires_finished_coproc_endpoints_before_later_redirects
(retired coproc names unbind, so element 0 must read unset) and one
executor_tests shellmath case; no new failures vs the pre-change
baseline on aarch64-linux-android.
caomengxuan666
added a commit
to jhermelink/rubash
that referenced
this pull request
Nov 5, 2026
…in_finish production) Refs rubash unixwin#2620, niu unixwin#863.
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.
Problem
array_element_parameter_valuereturnedSome("")for index 0 of an unset variable, so the parameter looked set-but-empty to the operators:Only
:-behaved (it treats null like unset too). A retired coproc name unbinds its array, so this also brokec_command_retires_finished_coproc_endpoints_before_later_redirects(c0=<>instead ofc0=<unset>).Fix (
src/executor/arrays/executor.rs)In the scalar-base arm, report the reference as unset (
None) when there is no storage and no live dynamic value; a set-but-empty scalar keeps its empty element 0. A dynamic scalar (RANDOM/SECONDS/LINENO...) reads live through element 0, shadowing stored seed text — the same dynamic-first precedence plain$nameexpansion uses. Probed against GNU bash 5.3 for-/:-/=/+on unset, set-empty and dynamic bases, plus the plain${Z[0]}case (still empty).Tests
cli_tests::unset_scalar_base_index_zero_is_unset_for_operators.cargo test --locked --test cli_tests: 466 passed, 0 failed (was 464 passed / 1 failed).cargo test --locked --test executor_tests: 1541 passed / 11 failed vs 1540 / 12 on the pristine-HEAD baseline (worktree, same device) — one extra fix (part_071 shellmath_decimal_divide), zero new failures. The 11 remaining fail identically at baseline: Android/Bionic signal numbering (kill/trap),ulimittext, Termux//PWD prefix — all platform environment, none touch this path.rustfmt-clean (printf/number.rshas a pre-existing fmt diff at HEAD; untouched here).