From 93a0fe95ba4f6dba4297276305b246694974de25 Mon Sep 17 00:00:00 2001 From: Vladimir Moskva Date: Tue, 11 Jan 2022 14:26:13 +0100 Subject: [PATCH] Allow escape characters \a \b \f \v (#1025) --- build/quote.go | 14 +++++++++++++- build/testdata/060.golden | 14 +++++++++----- build/testdata/060.in | 12 ++++++++---- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/build/quote.go b/build/quote.go index 6028c6b5c..50682eadc 100644 --- a/build/quote.go +++ b/build/quote.go @@ -27,9 +27,13 @@ import ( // unesc maps single-letter chars following \ to their actual values. var unesc = [256]byte{ + 'a': '\a', + 'b': '\b', + 'f': '\f', 'n': '\n', 'r': '\r', 't': '\t', + 'v': '\v', '\\': '\\', '\'': '\'', '"': '"', @@ -37,9 +41,13 @@ var unesc = [256]byte{ // esc maps escape-worthy bytes to the char that should follow \. var esc = [256]byte{ + '\a': 'a', + '\b': 'b', + '\f': 'f', '\n': 'n', '\r': 'r', '\t': 't', + '\v': 'v', '\\': '\\', '\'': '\'', '"': '"', @@ -49,9 +57,13 @@ var esc = [256]byte{ // in a string literal var escapable = [256]bool{ '\n': true, + 'a': true, + 'b': true, + 'f': true, 'n': true, 'r': true, 't': true, + 'v': true, 'x': true, '\'': true, '\\': true, @@ -138,7 +150,7 @@ func Unquote(quoted string) (s string, triple bool, err error) { // Ignore the escape and the line break. quoted = quoted[2:] - case 'n', 'r', 't', '\\', '\'', '"': + case 'a', 'b', 'f', 'n', 'r', 't', 'v', '\\', '\'', '"': // One-char escape buf.WriteByte(unesc[quoted[1]]) quoted = quoted[2:] diff --git a/build/testdata/060.golden b/build/testdata/060.golden index 9bee5b99a..b8e1b42e9 100644 --- a/build/testdata/060.golden +++ b/build/testdata/060.golden @@ -41,13 +41,17 @@ strings = [ r"\a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x43\y\z\0\1\2\3\4\5\6\7\8\9\\n", # contain incorrect escape sequences - "\\a'", - "\\a\"", - """\\a'""", - """\\a\"""", - "\\a\\b\\c\\d\\e\\f\\g\\h\\i\\j\\k\\l\\m\n\\o\\p\\q\r\\s\t\\u\\v\\wC\\y\\z\000\001\002\003\004\005\006\007\\8\\9", + "\\c'", + "\\c\"", + """\\c'""", + """\\c\"""", + "\a\b\\c\\d\\e\f\\g\\h\\i\\j\\k\\l\\m\n\\o\\p\\q\r\\s\t\\u\v\\wC\\y\\z\000\001\002\003\004\005\006\a\\8\\9", # correct escape sequences + """\a\b\f\n\r\t\v\007\010\ + """, + """\a\b\f +\r\t\v\a\b """, """ aa\\bb\n \ """, "\000\111\222", diff --git a/build/testdata/060.in b/build/testdata/060.in index bf869d64e..811cc1c5d 100644 --- a/build/testdata/060.in +++ b/build/testdata/060.in @@ -41,13 +41,17 @@ strings = [ r"\a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x43\y\z\0\1\2\3\4\5\6\7\8\9\\n", # contain incorrect escape sequences - "\a'", - '\a"', - """\a'""", - '''\a"''', + "\c'", + '\c"', + """\c'""", + '''\c"''', "\a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x43\y\z\0\1\2\3\4\5\6\7\8\9", # correct escape sequences + """\a\b\f\n\r\t\v\007\010\ + """, + '''\a\b\f\n\r\t\v\007\010\ + ''', """ aa\\bb\n \ """, "\000\111\222",