Skip to content

Commit

Permalink
Fix backquote in part of argument
Browse files Browse the repository at this point in the history
Fixes #25
  • Loading branch information
mattn committed Apr 25, 2019
1 parent 2b0d8a7 commit 0cbbbd6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion shellwords.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ loop:
if err != nil {
return nil, err
}
buf = out
buf = buf[:len(buf)-len(backtick)] + out
}
backtick = ""
backQuote = !backQuote
Expand Down
13 changes: 13 additions & 0 deletions shellwords_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,16 @@ func TestHaveRedirect(t *testing.T) {
t.Fatalf("Commands should be remaining")
}
}

func TestBackquoteInFlag(t *testing.T) {
parser := NewParser()
parser.ParseBacktick = true
args, err := parser.Parse("cmd -flag=`echo val1` -flag=val2")
if err != nil {
panic(err)
}
expected := []string{"cmd", "-flag=val1", "-flag=val2"}
if !reflect.DeepEqual(args, expected) {
t.Fatalf("Expected %#v, but %#v:", expected, args)
}
}

0 comments on commit 0cbbbd6

Please sign in to comment.