Repository navigation
fix: don't panic on :connect without a server name - #845
Open
Hitarth Jain (Yeagerist0) wants to merge 1 commit into
Open
Hitarth Jain (Yeagerist0) wants to merge 1 commit into
Hitarth Jain (Yeagerist0) wants to merge 1 commit into
Conversation
The command regex yields one empty argument for a bare :connect, so strings.Fields returns nothing and commandArgs[1:] panics.
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the change to handle :connect commands without a server name.
No open issues 🎉
What changed in this PR
Prevents sqlcmd from panicking when :connect is entered without a server name, returning the standard invalid-command error instead.
Changes:
- Reject empty parsed arguments before accessing the server name.
- Add parser-based regression tests for bare, whitespace-only, and comment-only
:connectcommands.
| File | Description |
|---|---|
| pkg/sqlcmd/connect_command_test.go | Adds regression tests for missing server names. |
| pkg/sqlcmd/commands.go | Guards empty arguments and removes a redundant check. |
Review effort: Balanced
Author
|
@microsoft-github-policy-service agree |
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.
Typing
:connectwith no server name panics:The
CONNECTregex yields one empty argument for a bare:connect, so thelen(args) == 0check passes,strings.Fieldsreturns an empty slice andcommandArgs[1:]panics. The existing test passes[]string{}, which the parser never produces here.The fix returns the usual invalid-command error. The new test goes through
matchCommand; its:connectand:CONNECTcases panic onmain.commands.gokeeps its CRLF line endings.Testing: the new test,
go build ./...andgo vet ./pkg/sqlcmdpass. I did not run the tests that need a SQL Server instance.AI disclosure: Claude Code found the bug and wrote the fix, test and this description; the results above are from local runs.