Skip to content

fix(unset): unbind assoc elements whose key is a quote, backslash or backtick (rubash#2657) - #3493

Merged
caomengxuan666 merged 1 commit into
masterfrom
ai-fix/rubash-2657
Nov 14, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
ai-fix/rubash-2657

Conversation

@arookieofc-ai

Copy link
Copy Markdown
Contributor

Fixes #2657.

unset -v dict["$k"] failed for associative keys that are a quote, backslash or backtick character: the ' and \ keys were rejected as not a valid identifier, and the backtick key was silently kept.

Root cause: the expanded operand is a W_ARRAYREF word, so GNU binds its subscript verbatim up to the last ] (VA_ONEWORD, tokenize_array_reference, arrayfunc.c:1166) - the quoting bytes are literal key data, not syntax. unset_array_element ran the quote-aware parse_array_subscript scan on the expanded text instead, which misreads all three: a lone quote opens a span that never closes, a backslash escapes the closer, a backtick opens a span.

Fix: unset_array_element gains a oneword flag (true only for the W_ARRAYREF call site). When set and the base is an associative array, the subscript splits at the first [ and the last ] with no quote/escape/backquote scan (split_oneword_array_subscript). The split stays off for indexed arrays and scalars (GNU rejects the same spellings there with not a valid identifier, and the quote-aware path already produces exactly that) and for the array_expand_once (VA_NOEXPAND-only, no VA_ONEWORD) call.

Oracle: GNU bash 5.3.20 (issue text) and 5.2.21 (box probes 2026-11-13). Verified GNU removes all three keys via dict["$k"] and dict[$k], removes a]b/a[b keys, and still rejects the indexed, scalar, whole-word double-quoted and empty-key spellings - rubash now matches all of these.

Regression tests: tests/issue2657_unset_assoc_quote_key_regressions.rs (10 tests: issue repro, one per key, unquoted expansion, bracket keys, plus guards for indexed/scalar/whole-word-quoted/empty-key).

Test results (box, CARGO_TARGET_DIR=/dev/shm):

  • new suite: 10 passed, 0 failed
  • cargo test --lib: 1246 passed, 0 failed, 4 ignored
  • neighbours issue651 (5), issue2703 (2), issue2946 (8), issue3024 (23), issue3343 (12): all pass
  • issue860: 6 passed, 11 failed - all 11 differ from expectation ONLY in the bash: vs binary-path diagnostic prefix (missing arg0 pin, rubash#2935 convention); 0 beyond-prefix mismatches, pre-existing, unrelated to this change.

Notes for the coordinator (not fixed here, one root cause per PR):

  • unset -v n["$k"] where n is a nameref to an assoc array with a quote key: GNU removes the element, rubash still reports not a valid identifier (the nameref path re-parses with the quote-aware scan).
  • unset -v arr["$k"] on an INDEXED array with a backtick key: GNU reports not a valid identifier (rc 1), rubash silently succeeds (rc 0, nothing removed) via the lib fallback; the '/\ cases already match GNU.

@caomengxuan666 caomengxuan666 added bug Something isn't working P2-medium 中:次要缺陷或边缘路径,排期修复 labels Nov 13, 2026
@caomengxuan666 caomengxuan666 self-assigned this Nov 13, 2026
@caomengxuan666

Copy link
Copy Markdown
Member

Thank you for the PR — and for the thorough write-up, including the GNU oracle notes and the two residuals left out of scope.

What was captured: this fixes #2657 (unset -v dict["$k"] failing for associative keys that are a quote, backslash or backtick), changing src/executor/unset_arrays.rs (+47/−5) and adding the 10-test regression suite tests/issue2657_unset_assoc_quote_key_regressions.rs. #2657 is open, P2-medium, gnu-baseline, in the 1.5.1 audit programme (assignment/array family), so this PR is homed there.

What happens next: per the owner's rule, external PRs are reviewed by the captain first — this one is queued for captain review, and I am not merging anything from intake. CI is being watched: three legs are currently red (Rust tests, Rust tests (macOS), GNU regression goldens and canaries), all failing at the "Run Rust library tests" step. The same three legs are red on master (run 43347552947, head 8a73f079), so at job level this looks pre-existing rather than PR-introduced — but the failing-step logs still need to be read, and CI's Rust tests job only runs a selected nextest table, so the new nail stem is not covered by CI; the captain's review will re-run the nails locally before any verdict. The PR body's note that the issue860 failures are pre-existing prefix-only mismatches is recorded as a claim to verify in that review, not confirmed here. The two residuals you noted (nameref-to-assoc quote key; indexed-array backtick key silently succeeding) are likewise recorded as not fixed here, for the captain to disposition.

No dates are promised; the captain's review comment will be the next step.

@caomengxuan666
caomengxuan666 merged commit 4817520 into master Nov 14, 2026
10 of 13 checks passed
caomengxuan666 added a commit that referenced this pull request Nov 14, 2026
…#3521)

Refs #3521 only — #3493 residual 1, not #3522 (indexed backtick
fallback untouched).

`unset -v n["$k"]` where n is a nameref to an assoc array reported
`not a valid identifier` for quote/backslash keys (backtick: `n:
not an array variable`; no -v: silent keep) while GNU removes the
element.

Root cause: a W_ARRAYREF word carries VA_ONEWORD|VA_NOEXPAND
(builtins/common.c:1050-1051); GNU tokenize_array_reference binds
the subscript verbatim up to the LAST `]` (arrayfunc.c:1312-1313)
and find_variable follows the nameref chain before
unbind_array_element runs with the same vflags (builtins/set.def:887,
akey = sub verbatim, arrayfunc.c:1186-1187). Rubash's
unset_through_nameref re-parsed the operand with the quote-aware
parse_array_subscript and re-called unset_array_element with
oneword=false, so the quote-aware scan failed and the element
survived.

Fix: unset_through_nameref gains the oneword flag (true at the
W_ARRAYREF call site, false elsewhere). Its subscripted-base arm
splits verbatim when oneword, follows the nameref chain to the
referenced array (find_variable; the plain-cell arm already walks
it), and re-calls unset_array_element with the same (arrayref,
oneword) pair as the direct W_ARRAYREF site — the two halves of
GNU's one vflags word. A None there falls through (no .or(Some(0)))
so the caller's validity gate reports GNU's `not a valid
identifier` for indexed/scalar referents. The plain-cell arm is
untouched: GNU applies valid_array_reference(cell, 0) there
(set.def:990-1010), and a quote/backtick-key cell cannot even be
created (declare -n rejects it).

Regression tests: tests/issue3521_unset_nameref_assoc_quote_key_regressions.rs
(13 tests; base 4 passed / 9 failed, head TBD on box).

## 本 PR 删除了什么

- src/executor/unset_arrays.rs 内共删除 7 行:两处旧的
  unset_through_nameref 调用表达式(改为带 oneword 参数的新调
  用形)、四处旧的 subscripted-arm 取指表达式(改为逐字拆分 +
  链跟随 + 同 vflags 重调)与一处旧函数签名行(签名增加
  oneword 参数)。
- 未删除任何文件、符号或公开 API:unset_through_nameref 与
  unset_array_element 均为 pub(in crate::executor) 内部面,非公
  开 API;其余均为新增代码与新增回归钉。

UNVERIFIED-BY-CAPTAIN
caomengxuan666 added a commit that referenced this pull request Nov 14, 2026
…#3521)

Refs #3521 only — #3493 residual 1, not #3522 (indexed backtick
fallback untouched).

`unset -v n["$k"]` where n is a nameref to an assoc array reported
`not a valid identifier` for quote/backslash keys (backtick: `n:
not an array variable`; no -v: silent keep) while GNU removes the
element.

Root cause: a W_ARRAYREF word carries VA_ONEWORD|VA_NOEXPAND
(builtins/common.c:1050-1051); GNU tokenize_array_reference binds
the subscript verbatim up to the LAST `]` (arrayfunc.c:1312-1313)
and find_variable follows the nameref chain before
unbind_array_element runs with the same vflags (builtins/set.def:887,
akey = sub verbatim, arrayfunc.c:1186-1187). Rubash's
unset_through_nameref re-parsed the operand with the quote-aware
parse_array_subscript and re-called unset_array_element with
oneword=false, so the quote-aware scan failed and the element
survived.

Fix: unset_through_nameref gains the oneword flag (true at the
W_ARRAYREF call site, false elsewhere). Its subscripted-base arm
splits verbatim when oneword, follows the nameref chain to the
referenced array (find_variable; the plain-cell arm already walks
it), and re-calls unset_array_element with the same (arrayref,
oneword) pair as the direct W_ARRAYREF site — the two halves of
GNU's one vflags word. A None there falls through (no .or(Some(0)))
so the caller's validity gate reports GNU's `not a valid
identifier` for indexed/scalar referents. The plain-cell arm is
untouched: GNU applies valid_array_reference(cell, 0) there
(set.def:990-1010), and a quote/backtick-key cell cannot even be
created (declare -n rejects it).

Regression tests: tests/issue3521_unset_nameref_assoc_quote_key_regressions.rs
(13 tests; base 4 passed / 9 failed, head TBD on box).

## 本 PR 删除了什么

- src/executor/unset_arrays.rs 内共删除 7 行:两处旧的
  unset_through_nameref 调用表达式(改为带 oneword 参数的新调
  用形)、四处旧的 subscripted-arm 取指表达式(改为逐字拆分 +
  链跟随 + 同 vflags 重调)与一处旧函数签名行(签名增加
  oneword 参数)。
- 未删除任何文件、符号或公开 API:unset_through_nameref 与
  unset_array_element 均为 pub(in crate::executor) 内部面,非公
  开 API;其余均为新增代码与新增回归钉。

UNVERIFIED-BY-CAPTAIN
caomengxuan666 added a commit that referenced this pull request Nov 14, 2026
…#3521)

Refs #3521 only — #3493 residual 1, not #3522 (indexed backtick
fallback untouched).

`unset -v n["$k"]` where n is a nameref to an assoc array reported
`not a valid identifier` for quote/backslash keys (backtick: `n:
not an array variable`; no -v: silent keep) while GNU removes the
element.

Root cause: a W_ARRAYREF word carries VA_ONEWORD|VA_NOEXPAND
(builtins/common.c:1050-1051); GNU tokenize_array_reference binds
the subscript verbatim up to the LAST `]` (arrayfunc.c:1312-1313)
and find_variable follows the nameref chain before
unbind_array_element runs with the same vflags (builtins/set.def:887,
akey = sub verbatim, arrayfunc.c:1186-1187). Rubash's
unset_through_nameref re-parsed the operand with the quote-aware
parse_array_subscript and re-called unset_array_element with
oneword=false, so the quote-aware scan failed and the element
survived.

Fix: unset_through_nameref gains the oneword flag (true at the
W_ARRAYREF call site, false elsewhere). Its subscripted-base arm
splits verbatim when oneword, follows the nameref chain to the
referenced array (find_variable; the plain-cell arm already walks
it), and re-calls unset_array_element with the same (arrayref,
oneword) pair as the direct W_ARRAYREF site — the two halves of
GNU's one vflags word. A None there falls through (no .or(Some(0)))
so the caller's validity gate reports GNU's `not a valid
identifier` for indexed/scalar referents. The plain-cell arm is
untouched: GNU applies valid_array_reference(cell, 0) there
(set.def:990-1010), and a quote/backtick-key cell cannot even be
created (declare -n rejects it).

Regression tests: tests/issue3521_unset_nameref_assoc_quote_key_regressions.rs
(13 tests; base 4 passed / 9 failed, head TBD on box).

## 本 PR 删除了什么

- src/executor/unset_arrays.rs 内共删除 7 行:两处旧的
  unset_through_nameref 调用表达式(改为带 oneword 参数的新调
  用形)、四处旧的 subscripted-arm 取指表达式(改为逐字拆分 +
  链跟随 + 同 vflags 重调)与一处旧函数签名行(签名增加
  oneword 参数)。
- 未删除任何文件、符号或公开 API:unset_through_nameref 与
  unset_array_element 均为 pub(in crate::executor) 内部面,非公
  开 API;其余均为新增代码与新增回归钉。

UNVERIFIED-BY-CAPTAIN
caomengxuan666 added a commit that referenced this pull request Nov 14, 2026
…#3521)

Refs #3521 only — #3493 residual 1, not #3522 (indexed backtick
fallback untouched).

`unset -v n["$k"]` where n is a nameref to an assoc array reported
`not a valid identifier` for quote/backslash keys (backtick: `n:
not an array variable`; no -v: silent keep) while GNU removes the
element.

Root cause: a W_ARRAYREF word carries VA_ONEWORD|VA_NOEXPAND
(builtins/common.c:1050-1051); GNU tokenize_array_reference binds
the subscript verbatim up to the LAST `]` (arrayfunc.c:1312-1313)
and find_variable follows the nameref chain before
unbind_array_element runs with the same vflags (builtins/set.def:887,
akey = sub verbatim, arrayfunc.c:1186-1187). Rubash's
unset_through_nameref re-parsed the operand with the quote-aware
parse_array_subscript and re-called unset_array_element with
oneword=false, so the quote-aware scan failed and the element
survived.

Fix: unset_through_nameref gains the oneword flag (true at the
W_ARRAYREF call site, false elsewhere). Its subscripted-base arm
splits verbatim when oneword, follows the nameref chain to the
referenced array (find_variable; the plain-cell arm already walks
it), and re-calls unset_array_element with the same (arrayref,
oneword) pair as the direct W_ARRAYREF site — the two halves of
GNU's one vflags word. A None there falls through (no .or(Some(0)))
so the caller's validity gate reports GNU's `not a valid
identifier` for indexed/scalar referents. The plain-cell arm is
untouched: GNU applies valid_array_reference(cell, 0) there
(set.def:990-1010), and a quote/backtick-key cell cannot even be
created (declare -n rejects it).

Regression tests: tests/issue3521_unset_nameref_assoc_quote_key_regressions.rs
(13 tests; base 4 passed / 9 failed, head TBD on box).

## 本 PR 删除了什么

- src/executor/unset_arrays.rs 内共删除 7 行:两处旧的
  unset_through_nameref 调用表达式(改为带 oneword 参数的新调
  用形)、四处旧的 subscripted-arm 取指表达式(改为逐字拆分 +
  链跟随 + 同 vflags 重调)与一处旧函数签名行(签名增加
  oneword 参数)。
- 未删除任何文件、符号或公开 API:unset_through_nameref 与
  unset_array_element 均为 pub(in crate::executor) 内部面,非公
  开 API;其余均为新增代码与新增回归钉。

UNVERIFIED-BY-CAPTAIN
caomengxuan666 added a commit that referenced this pull request Nov 14, 2026
…m (Refs #3521)

Refs rubash#3521 only — #3493 residual 1, not #3522 (indexed backtick fallback untouched).

## 现象

`unset -v n["$k"]`(n 为指向关联数组的 nameref,引号/反斜杠/反引号键)报 `not a valid identifier`(反引号:`n: not an array variable`;无 -v:静默保留),GNU 删除该元素。

## 根因

W_ARRAYREF 词带 VA_ONEWORD|VA_NOEXPAND(builtins/common.c:1050-1051);GNU tokenize_array_reference 逐字取下标到最后一个 `]`(arrayfunc.c:1307-1308),find_variable 跟 nameref 链后 unbind_array_element 以同一 vflags 执行(builtins/set.def:887,akey = sub 逐字,arrayfunc.c:1169)。rubash 的 unset_through_nameref 以 quote-aware 的 parse_array_subscript 重解析并以 oneword=false 重调 unset_array_element,走不到 #3493 的逐字路径。

## 修复

unset_through_nameref 增加 oneword 参数(W_ARRAYREF 调点传 true,其余传 false)。其下标臂在 oneword 时逐字拆分、跟 nameref 链到被指数组、再以与直接 W_ARRAYREF 调点相同的 (arrayref, oneword) 对重调 unset_array_element——即 GNU 同一个 vflags 词的两半;oneword 下 None 直接落空(不 .or(Some(0))),由调用方有效性门报 GNU 的 `not a valid identifier`(索引/标量被指对象)。plain-cell 臂不动:GNU 在该处用 valid_array_reference(cell, 0)(set.def:990-1010),且引号/反引号键的 cell 根本建不出来(declare -n 拒收)。

## 回归钉(队长复核轮实测,卷宗 review-3526/CAPTAIN-VERIFY.md)

tests/issue3521_unset_nameref_assoc_quote_key_regressions.rs(13 tests:复现循环、单键 ×3、非引号展开、括号键、无 -v、nameref 链(引号键 + 素键对照);守卫:索引/标量/整词引号/空键)。基底 fail-first 4 passed / 9 failed(9 红逐名即 8 正向面 + 素键链对照,4 绿恰为 4 守卫);头 **13/13**。相邻面:651 5/5、2703 2/2、2946 8/8、3024 23/23、3343 12/12、2657 10/10。Lib 双边(bin-first):头 1247/0/4 = 基底 1247/0/4,名集差 ∅。`RUSTFLAGS="-D warnings"` 双边 rc=0,各 37 次带标志调用,0 warning。邻接面探针 vs GNU 5.3.20:头/GNU 日志各 555 字节,diff 0 字节。头 CI 三红唯一失败名 issue2875(#3292 基线)。与 live tip 交集为 ∅(复核末尾对 4e21e7b 重算,合入时队长再核至 93249de,区间文件无重叠)。

## 本 PR 删除了什么

- src/executor/unset_arrays.rs 内共删除 7 行:两处旧的 unset_through_nameref 调用表达式(改为带 oneword 参数的新调用形)、四处旧的 subscripted-arm 取指表达式(改为逐字拆分 + 链跟随 + 同 vflags 重调)与一处旧函数签名行(签名增加 oneword 参数)。
- 未删除任何文件、符号或公开 API:unset_through_nameref 与 unset_array_element 均为 pub(in crate::executor) 内部面,非公开 API;其余均为新增代码与新增回归钉。

Refs #3521
@arookieofc-ai
arookieofc-ai deleted the ai-fix/rubash-2657 branch November 15, 2026 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working P2-medium 中:次要缺陷或边缘路径,排期修复

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[upstream] Arrays: unset of an associative element whose key is a quote/backslash character fails as "not a valid identifier"

2 participants