fix: stop version-flag scan at the remote command boundary#7
Merged
Conversation
handleVersionFlag scanned every argument, so a bare -v/-V/--version token inside an unquoted remote command (e.g. `sshx -h=host grep -v foo`) was mistaken for a version request and printed the version with exit 0 instead of running the command. Stop the scan at the first positional argument so only a version flag that precedes the command is honored, and add a table test covering the recognized and ignored cases. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1b413e9 to
bddec0a
Compare
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
Follow-up hardening found during an overall review of the version/skill work.
handleVersionFlagscanned every argument for--version/-v/-V. Because a remote command is the trailing argument, a bare-vtoken in an unquoted command (e.g.sshx -h=host grep -v foo) was mistaken for a version request — sshx printed the version and exited0instead of running the command. This is misleading for scripts/agents (an unexpectedexit 0).Fix
Stop the scan at the first positional argument, so only a version flag that appears before the remote command is honored.
sshx --version/-v/-V✓ (unchanged)sshx -h=host --version✓ (flags only, still prints)sshx -h=host grep -v foo→ now runs the command (the-vis no longer hijacked)Adds a table test (
cmd/sshx/main_test.go) covering recognized vs. ignored cases, and a CHANGELOG note.Verification
gofmt/go vetclean;go test ./...passes (newTestHandleVersionFlagincluded).-ldflags -X main.Version=test123confirms all four cases above.