fix(cli): reject --index 0 and validate braced substitution variable names#494
Merged
Conversation
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>
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.
Summary
Two correctness fixes for invalid CLI/compose input that was previously
accepted silently.
1.
--index 0rejected as out of range (replica_name_at)The 1-based
--indexflag (used byexec,cp,commit,export)mapped index
0to replica index0via(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 on0with 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 alookup key containing spaces/dots. The name is now collected with
is_var_char— matching the unbraced$VARpath and the compose-specgrammar — and any trailing junk before a modifier delimiter is rejected via
a new
InvalidSubstitutionerror. 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, andtest --lib --all-features(660 passing) all green. Public API andbehaviour for valid input are unchanged.
Closes #483