fix: Invalid handling of empty values in sqlcmd by debarshibasak · Pull Request #708 · microsoft/go-sqlcmd

The built sqlcmd is throwing panic errors, for the empty values. For eg.

SQLCMDPASSWORD=<somepassword> ./sqlcmd -S <ip> -U 'sa' -d '' -Q "SELECT name FROM sys.databases WHERE name NOT IN ('tempdb','sys','msdb', 'model')" -b

Throws:

runtime error: index out of range [0] with length 0

goroutine 1 [running]:
github.com/microsoft/go-sqlcmd/cmd/sqlcmd.checkDefaultValue({0xc000034150, 0x9, 0xefcf38?}, 0x4)
	/__w/1/s/go-sqlcmd/cmd/sqlcmd/sqlcmd.go:320 +0x2da
github.com/microsoft/go-sqlcmd/cmd/sqlcmd.convertOsArgs({0xc000034150, 0x9, 0x9})
	/__w/1/s/go-sqlcmd/cmd/sqlcmd/sqlcmd.go:302 +0x22a
github.com/microsoft/go-sqlcmd/cmd/sqlcmd.Execute({0x122eaac, 0x6})
	/__w/1/s/go-sqlcmd/cmd/sqlcmd/sqlcmd.go:274 +0x150
main.main()
	/__w/1/s/go-sqlcmd/cmd/modern/main.go:52 +0x209

After the fix:

name

pubs

I have validated for rest of the flags too.