github.com/divyam234/rclone@v1.64.1/cmd/serve/sftp/connection_test.go (about) 1 //go:build !plan9 2 // +build !plan9 3 4 package sftp 5 6 import ( 7 "fmt" 8 "testing" 9 10 "github.com/stretchr/testify/assert" 11 ) 12 13 func TestShellEscape(t *testing.T) { 14 for i, test := range []struct { 15 unescaped, escaped string 16 }{ 17 {"", ""}, 18 {"/this/is/harmless", "/this/is/harmless"}, 19 {"$(rm -rf /)", "\\$\\(rm\\ -rf\\ /\\)"}, 20 {"/test/\n", "/test/'\n'"}, 21 {":\"'", ":\\\"\\'"}, 22 } { 23 got := shellUnEscape(test.escaped) 24 assert.Equal(t, test.unescaped, got, fmt.Sprintf("Test %d unescaped = %q", i, test.unescaped)) 25 } 26 }