From f88ca9dbf4f96a989fae20d7aa7e5df8de6e4fd1 Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Sun, 16 May 2021 12:33:50 +1000 Subject: [PATCH] Added ability to escape double quotes in double quotes --- pkg/yqlib/expression_processing_test.go | 5 +++++ pkg/yqlib/expression_tokeniser.go | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/yqlib/expression_processing_test.go b/pkg/yqlib/expression_processing_test.go index 93cb2047..aac09934 100644 --- a/pkg/yqlib/expression_processing_test.go +++ b/pkg/yqlib/expression_processing_test.go @@ -12,6 +12,11 @@ var pathTests = []struct { expectedTokens []interface{} expectedPostFix []interface{} }{ + { + `"\""`, + append(make([]interface{}, 0), "\" (string)"), + append(make([]interface{}, 0), "\" (string)"), + }, { `[]|join(".")`, append(make([]interface{}, 0), "[", "EMPTY", "]", "PIPE", "JOIN", "(", ". (string)", ")"), diff --git a/pkg/yqlib/expression_tokeniser.go b/pkg/yqlib/expression_tokeniser.go index 888b882d..e509c848 100644 --- a/pkg/yqlib/expression_tokeniser.go +++ b/pkg/yqlib/expression_tokeniser.go @@ -189,6 +189,7 @@ func stringValue(wrapped bool) lex.Action { if wrapped { value = unwrap(value) } + value = strings.ReplaceAll(value, "\\\"", "\"") return &token{TokenType: operationToken, Operation: createValueOperation(value, value)}, nil } } @@ -334,7 +335,7 @@ func initLexer() (*lex.Lexer, error) { lexer.Add([]byte(`[Nn][Uu][Ll][Ll]`), nullValue()) lexer.Add([]byte(`~`), nullValue()) - lexer.Add([]byte(`"[^"]*"`), stringValue(true)) + lexer.Add([]byte(`"([^"\\]*(\\.[^"\\]*)*)"`), stringValue(true)) lexer.Add([]byte(`strenv\([^\)]+\)`), envOp(true)) lexer.Add([]byte(`env\([^\)]+\)`), envOp(false))