diff --git a/eval_test.go b/eval_test.go index 23400d32..e97bc1f1 100644 --- a/eval_test.go +++ b/eval_test.go @@ -71,6 +71,18 @@ var gEvalTests = []struct { []expr{&callExpr{"echo", []string{"helloworld"}}}, }, + { + `echo "hello\0world"`, + []string{"echo", "hello\000world", "\n"}, + []expr{&callExpr{"echo", []string{"hello\000world"}}}, + }, + + { + `echo "hello\101world"`, + []string{"echo", "hello\101world", "\n"}, + []expr{&callExpr{"echo", []string{"hello\101world"}}}, + }, + { `echo hello\ world`, []string{"echo", "hello world", "\n"}, diff --git a/scan.go b/scan.go index 68cf5c73..622e20fa 100644 --- a/scan.go +++ b/scan.go @@ -4,6 +4,7 @@ import ( "io" "io/ioutil" "log" + "strconv" "unicode" ) @@ -84,6 +85,10 @@ func isSpace(b byte) bool { return unicode.IsSpace(rune(b)) } +func isDigit(b byte) bool { + return unicode.IsDigit(rune(b)) +} + func isPrefix(b byte) bool { // TODO: how to differentiate slash in path vs search? return b == '$' || b == '!' || b == '&' // || b == '/' || b == '?' @@ -228,7 +233,20 @@ scan: case 'v': buf = append(buf, '\v') } - s.next() + if isDigit(s.chr) { + var oct []byte + for isDigit(s.chr) { + oct = append(oct, s.chr) + s.next() + } + n, err := strconv.ParseInt(string(oct), 8, 0) + if err != nil { + log.Printf("scanning: %s", err) + } + buf = append(buf, byte(n)) + } else { + s.next() + } } else { buf = append(buf, s.chr) s.next()