diff --git a/eval_test.go b/eval_test.go index 4a8c47e1..b3111450 100644 --- a/eval_test.go +++ b/eval_test.go @@ -84,6 +84,18 @@ var gEvalTests = []struct { []expr{&callExpr{"echo", []string{"hello\101world"}, 1}}, }, + { + `echo "hello\1011world"`, + []string{"echo", "hello\1011world", "\n"}, + []expr{&callExpr{"echo", []string{"hello\1011world"}, 1}}, + }, + + { + `tty-write "\0337\0338"`, + []string{"tty-write", "\0337\0338", "\n"}, + []expr{&callExpr{"tty-write", []string{"\0337\0338"}, 1}}, + }, + { `echo hello\ world`, []string{"echo", "hello world", "\n"}, diff --git a/scan.go b/scan.go index e0deab2c..cad03335 100644 --- a/scan.go +++ b/scan.go @@ -237,8 +237,10 @@ scan: case s.chr == 'v': buf = append(buf, '\v') case isDigit(s.chr): + // like C, an octal escape is at most three digits long + // so that "\0337" is read as "\033" followed by "7" var oct []byte - for isDigit(s.chr) { + for len(oct) < 3 && isDigit(s.chr) { oct = append(oct, s.chr) s.next() }