fix: invalid handling of empty values in sqlcmd#708
Conversation
@microsoft-github-policy-service agree [company="Adaptive"] |
@microsoft-github-policy-service agree |
@microsoft-github-policy-service agree company="Adaptive" |
There was a problem hiding this comment.
Pull request overview
Fixes a panic in the legacy cmd/sqlcmd argument-rewriting logic when a flag is followed by an empty string value (e.g., -d ""), ensuring sqlcmd can accept intentionally empty values without crashing.
Changes:
- Make flag detection safe for empty-string arguments by guarding index access and reusing
isFlagincheckDefaultValue. - Add a unit test case covering a flag with an explicit empty value (
-d "") to prevent regression.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| cmd/sqlcmd/sqlcmd.go | Prevents panics by making isFlag safe on empty strings and using it in checkDefaultValue when checking the next arg. |
| cmd/sqlcmd/sqlcmd_test.go | Adds a regression test ensuring empty flag values (e.g., -d "") are preserved and don’t crash conversion. |
|
Fixes #750 |
|
Thanks for the fix @debarshibasak and apologies for the long delay getting CI unblocked on this one! The root-cause analysis is spot on, and routing both call sites through Before we merge, could you make a couple of small tweaks? 1. Rebase onto current
|
The built sqlcmd is throwing panic errors, for the empty values. For eg.
Throws:
After the fix:
name
pubs
I have validated for rest of the flags too.