Skip to content

fix(executor): ${#@x} admits only valid @xform suffix (Refs #2711) - #3687

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/2711-length-op-suffix
Nov 15, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/2711-length-op-suffix

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Problem

echo "<${#@: 2: 1}>", <${#@%b}>, <${#@:-2}> expanded to empty output where GNU reports bad substitution (rc 1). ${#*: 1} was already rejected.

Root cause

For ${#<name>} where <name> is not a valid length operand, GNU treats # as the $# parameter and requires the remainder to be a parameter operator (parameter_brace_expand, subst.c:9931-9941: the #-led name must consume the whole body up to }). The @ in that position is the transform operator, and valid_parameter_transform (subst.c:8898-8922) admits EXACTLY one char from {a,A,K,k,E,P,Q,U,u,L} — ${#@Q} is valid ('2' under set -- ab cd, WSL bash 5.3.20 probe), ${#@:}/${#@%b}/${#@:-2} are not.

Rubash's is_length_operator_expression admitted @ followed by ANY text, so those shapes passed the expansion-error pre-scan and silently produced nothing.

Fix

is_length_operator_expression now requires the @ remainder to be exactly one valid transform char. Controls ${#@}, ${#*}, ${#arr[@]}, ${#v} unchanged (they never reached this arm).

Test legs

  • cargo test --test issue2711_hash_at_operator_suffix: 8/8 green (was 5/8 on master; the 3 RED cells were ${#@: 2: 1}, ${#@%b}, ${#@:-2})
  • GNU reference: subst.c:8898-8922 valid_parameter_transform, subst.c:9931-9941
  • WSL bash 5.3.20 probe: all four bad shapes → bad substitution rc 1; ${#@Q} → '2'
  • fmt: cargo fmt hit Windows os error 206; used per-file rustfmt --edition 2021 as sanctioned fallback

Generated with Devin

GNU subst.c:8898-8922 valid_parameter_transform: the `@` operator in
${#@x} admits exactly one transform char from {a,A,K,k,E,P,Q,U,u,L};
subst.c:9931-9941 then requires the `#`-led name to consume the whole
body up to `}`, so `${#@: 2: 1}`, `${#@%b}` and `${#@:-2}`
are bad substitution while `${#@q}` is `$#` under the Q transform.

The length-remainder validator admitted `@` + anything; it now
requires exactly one valid transform char. `${#@}`/`${#*}`,
`${#arr[@]}`, `${#v}` controls unchanged.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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.

1 participant