Skip to content

Commit

Permalink
resolve vars in error and out commands
Browse files Browse the repository at this point in the history
  • Loading branch information
shueybubbles committed Jun 3, 2024
1 parent 9cd8538 commit 77dcb83
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pkg/sqlcmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,11 @@ func outCommand(s *Sqlcmd, args []string, line uint) error {
case strings.EqualFold(args[0], "stderr"):
s.SetOutput(os.Stderr)
default:
o, err := os.OpenFile(args[0], os.O_TRUNC|os.O_CREATE|os.O_WRONLY, 0o644)
filePath, err := resolveArgumentVariables(s, []rune(args[0]), true)
if err != nil {
return err
}
o, err := os.OpenFile(filePath, os.O_TRUNC|os.O_CREATE|os.O_WRONLY, 0o644)
if err != nil {
return InvalidFileError(err, args[0])
}
Expand Down Expand Up @@ -298,7 +302,11 @@ func errorCommand(s *Sqlcmd, args []string, line uint) error {
case strings.EqualFold(args[0], "stdout"):
s.SetError(os.Stdout)
default:
o, err := os.OpenFile(args[0], os.O_TRUNC|os.O_CREATE|os.O_WRONLY, 0o644)
filePath, err := resolveArgumentVariables(s, []rune(args[0]), true)
if err != nil {
return err
}
o, err := os.OpenFile(filePath, os.O_TRUNC|os.O_CREATE|os.O_WRONLY, 0o644)
if err != nil {
return InvalidFileError(err, args[0])
}
Expand Down Expand Up @@ -549,7 +557,7 @@ func xmlCommand(s *Sqlcmd, args []string, line uint) error {
func resolveArgumentVariables(s *Sqlcmd, arg []rune, failOnUnresolved bool) (string, error) {
var b *strings.Builder
end := len(arg)
for i := 0; i < end; {
for i := 0; i < end && !s.Connect.DisableVariableSubstitution; {
c, next := arg[i], grab(arg, i+1, end)
switch {
case c == '$' && next == '(':
Expand Down

0 comments on commit 77dcb83

Please sign in to comment.