From 6982ffe4cf4992e6d6bc4a7710d9e30782814aee Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Mon, 5 Aug 2019 22:24:12 +0300 Subject: [PATCH] allow double backslash escape without quotes Related #142 --- eval_test.go | 6 ++++++ scan.go | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/eval_test.go b/eval_test.go index cc6668a..94c0e3e 100644 --- a/eval_test.go +++ b/eval_test.go @@ -101,6 +101,12 @@ var gEvalTests = []struct { []expr{&callExpr{"echo", []string{"hello\nworld"}, 1}}, }, + { + `echo hello\\world`, + []string{"echo", `hello\world`, "\n"}, + []expr{&callExpr{"echo", []string{`hello\world`}, 1}}, + }, + { `echo hello\zworld`, []string{"echo", "helloworld", "\n"}, diff --git a/scan.go b/scan.go index b9c5726..6159876 100644 --- a/scan.go +++ b/scan.go @@ -293,7 +293,7 @@ scan: for !s.eof && !isSpace(s.chr) && s.chr != ';' && s.chr != '#' { if s.chr == '\\' { s.next() - if isSpace(s.chr) { + if isSpace(s.chr) || s.chr == '\\' { buf = append(buf, s.chr) s.next() } else {