From 0482340d5e9354db00b941616a95559081035ce1 Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Fri, 25 Oct 2019 20:50:00 +0300 Subject: [PATCH] keep trailing backslash during reverse escape --- misc.go | 3 +++ misc_test.go | 2 ++ 2 files changed, 5 insertions(+) diff --git a/misc.go b/misc.go index eea86dc9..14e23164 100644 --- a/misc.go +++ b/misc.go @@ -75,6 +75,9 @@ func unescape(s string) string { esc = false buf = append(buf, r) } + if esc { + buf = append(buf, '\\') + } return string(buf) } diff --git a/misc_test.go b/misc_test.go index a3833011..920f99a7 100644 --- a/misc_test.go +++ b/misc_test.go @@ -86,6 +86,7 @@ func TestEscape(t *testing.T) { {`foo#bar`, `foo\#bar`}, {`foo\tbar`, `foo\\tbar`}, {"foo\tbar", "foo\\\tbar"}, + {`foo\`, `foo\\`}, } for _, test := range tests { @@ -110,6 +111,7 @@ func TestUnescape(t *testing.T) { {`foo\#bar`, `foo#bar`}, {`foo\\tbar`, `foo\tbar`}, {"foo\\\tbar", "foo\tbar"}, + {`foo\`, `foo\`}, } for _, test := range tests {