Skip to content

fix(cli): reject --index 0 and validate braced substitution variable names#494

Merged
Jaro-c merged 2 commits into
developfrom
fix/cli-index-and-var-validation
Jun 19, 2026
Merged

fix(cli): reject --index 0 and validate braced substitution variable names#494
Jaro-c merged 2 commits into
developfrom
fix/cli-index-and-var-validation

Conversation

@Jaro-c

@Jaro-c Jaro-c commented Jun 19, 2026

Copy link
Copy Markdown
Member

Summary

Two correctness fixes for invalid CLI/compose input that was previously
accepted silently.

1. --index 0 rejected as out of range (replica_name_at)

The 1-based --index flag (used by exec, cp, commit, export)
mapped index 0 to replica index 0 via (i as usize).saturating_sub(1),
silently returning the first replica instead of rejecting the invalid
1-based index. It now uses checked_sub(1) and errors on 0 with a clear
"indexes are 1-based" message.

2. Braced substitution variable names validated (parse_braced_var)

${...} name collection accumulated any character that was not a
}/:/-/+/? delimiter, so ${FOO BAR} and ${FOO.BAR} produced a
lookup key containing spaces/dots. The name is now collected with
is_var_char — matching the unbraced $VAR path and the compose-spec
grammar — and any trailing junk before a modifier delimiter is rejected via
a new InvalidSubstitution error. Valid forms (${FOO}, ${FOO:-default},
including defaults that contain spaces/dots) are unaffected.

Tests

  • replica_name_at: index 0 → error, index 1 → first replica, index N →
    Nth replica, out-of-range → error, None → first replica.
  • parse_braced_var: ${FOO BAR} → error, ${FOO.BAR} → error, ${FOO}
    and ${FOO:-default} → valid.

cargo fmt, clippy -D warnings, build --all-features, and
test --lib --all-features (660 passing) all green. Public API and
behaviour for valid input are unchanged.

Closes #483

Jaro-c added 2 commits June 19, 2026 00:57
The 1-based `--index` used by exec/cp/commit/export mapped index 0 to
replica index 0 via `saturating_sub(1)`, silently returning the first
replica instead of rejecting the invalid index. Use `checked_sub(1)` and
error on 0 with a clear 1-based message.

Signed-off-by: Jaro-c <75870284+Jaro-c@users.noreply.github.com>
`parse_braced_var` accumulated any non-delimiter character into the
`${...}` name, so `${FOO BAR}` or `${FOO.BAR}` produced a lookup key
containing spaces or dots. Collect the name with `is_var_char` (matching
the unbraced $VAR path and the compose-spec grammar) and reject trailing
junk before a modifier delimiter via a new InvalidSubstitution error.

Signed-off-by: Jaro-c <75870284+Jaro-c@users.noreply.github.com>
@Jaro-c Jaro-c merged commit d25d2bf into develop Jun 19, 2026
13 checks passed
@Jaro-c Jaro-c deleted the fix/cli-index-and-var-validation branch June 19, 2026 06:13
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