예제 #1
0
func ExampleQuote() {
	filename := "myfile; rm -rf /"
	prog := "/bin/ls"
	unescapedCommand := strings.Join([]string{prog, filename}, " ")
	escapedCommand := strings.Join([]string{prog, shellescape.Quote(filename)}, " ")

	fmt.Println(unescapedCommand)
	fmt.Println(escapedCommand)
	// Output:
	// /bin/ls myfile; rm -rf /
	// /bin/ls 'myfile; rm -rf /'
}
예제 #2
0
func main() {
	firstScan := true
	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		if firstScan {
			firstScan = false
		} else {
			fmt.Printf(" ")
		}
		fmt.Printf("%s", shellescape.Quote(scanner.Text()))
	}
}
예제 #3
0
func TestUnquotedString(t *testing.T) {
	s := shellescape.Quote(`no quotes`)
	expected := `'no quotes'`
	assertEqual(t, s, expected)
}
예제 #4
0
func TestSingleQuotedString(t *testing.T) {
	s := shellescape.Quote(`'single quoted'`)
	expected := `''"'"'single quoted'"'"''`
	assertEqual(t, s, expected)
}
예제 #5
0
func TestDoubleQuotedString(t *testing.T) {
	s := shellescape.Quote(`"double quoted"`)
	expected := `'"double quoted"'`
	assertEqual(t, s, expected)
}
예제 #6
0
func TestEmptyString(t *testing.T) {
	s := shellescape.Quote("")
	expected := "''"
	assertEqual(t, s, expected)
}