-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathcommand_test.go
33 lines (29 loc) · 945 Bytes
/
command_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package log4shell
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestCommandLineToArgs(t *testing.T) {
exe1 := "exe1"
exe2 := `"exe2 arg1"`
for _, testdata := range [...]*struct {
cmd string
args []string
}{
{"net", []string{"net"}},
{`net -a -b`, []string{"net", "-a", "-b"}},
{`net -a -b "a"`, []string{"net", "-a", "-b", "a"}},
{`"net net"`, []string{"net net"}},
{`"net\net"`, []string{`net\net`}},
{`"net\net net"`, []string{`net\net net`}},
{`net -a \"net`, []string{"net", "-a", `"net`}},
{`net -a ""`, []string{"net", "-a", ""}},
{`""net"" -a -b`, []string{"net", "-a", "-b"}},
{`"""net""" -a`, []string{`"net"`, "-a"}},
} {
args := CommandLineToArgs(exe1 + " " + testdata.cmd)
require.Equal(t, append([]string{"exe1"}, testdata.args...), args)
args = CommandLineToArgs(exe2 + " " + testdata.cmd)
require.Equal(t, append([]string{"exe2 arg1"}, testdata.args...), args)
}
}