(t *testing.T)
| 12 | ) |
| 13 | |
| 14 | func TestShellQuote(t *testing.T) { |
| 15 | tests := []struct { |
| 16 | name string |
| 17 | input string |
| 18 | expected string |
| 19 | }{ |
| 20 | {"empty string", "", "''"}, |
| 21 | {"simple word", "hello", "'hello'"}, |
| 22 | {"with spaces", "hello world", "'hello world'"}, |
| 23 | {"with single quote", "it's", "'it'\\''s'"}, |
| 24 | {"with double quotes", `say "hi"`, `'say "hi"'`}, |
| 25 | {"with backticks", "echo `whoami`", "'echo `whoami`'"}, |
| 26 | {"command substitution", "$(rm -rf /)", "'$(rm -rf /)'"}, |
| 27 | {"semicolon injection", "foo; rm -rf /", "'foo; rm -rf /'"}, |
| 28 | {"pipe injection", "foo | cat /etc/passwd", "'foo | cat /etc/passwd'"}, |
| 29 | {"ampersand injection", "foo && evil", "'foo && evil'"}, |
| 30 | {"newline injection", "foo\nbar", "'foo\nbar'"}, |
| 31 | {"tab character", "foo\tbar", "'foo\tbar'"}, |
| 32 | {"path with spaces", "/home/user/my docs/file.txt", "'/home/user/my docs/file.txt'"}, |
| 33 | {"dollar variable", "$HOME/.bashrc", "'$HOME/.bashrc'"}, |
| 34 | {"backslash", "foo\\bar", "'foo\\bar'"}, |
| 35 | {"multiple single quotes", "it's a 'test'", "'it'\\''s a '\\''test'\\'''"}, |
| 36 | {"glob characters", "*.txt", "'*.txt'"}, |
| 37 | {"unicode characters", "hello 世界", "'hello 世界'"}, |
| 38 | } |
| 39 | |
| 40 | for _, tc := range tests { |
| 41 | t.Run(tc.name, func(t *testing.T) { |
| 42 | result := ShellQuote(tc.input) |
| 43 | assert.Equal(t, tc.expected, result) |
| 44 | }) |
| 45 | } |
| 46 | } |
nothing calls this directly
no test coverage detected