Пример #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)
}