github.com/artpar/rclone@v1.67.3/cmd/serve/sftp/connection_test.go (about)

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