diff --git a/pkg/yqlib/expression_processing_test.go b/pkg/yqlib/expression_processing_test.go index 2b2f7060..0af22b9f 100644 --- a/pkg/yqlib/expression_processing_test.go +++ b/pkg/yqlib/expression_processing_test.go @@ -7,11 +7,24 @@ import ( "github.com/mikefarah/yq/v4/test" ) +var variableWithNewLine = `"cat +"` + var pathTests = []struct { path string expectedTokens []interface{} expectedPostFix []interface{} }{ + { + ".a\n", + append(make([]interface{}, 0), "a"), + append(make([]interface{}, 0), "a"), + }, + { + variableWithNewLine, + append(make([]interface{}, 0), "cat\n (string)"), + append(make([]interface{}, 0), "cat\n (string)"), + }, { `.[0]`, append(make([]interface{}, 0), "SELF", "TRAVERSE_ARRAY", "[", "0 (int64)", "]"), diff --git a/pkg/yqlib/expression_tokeniser.go b/pkg/yqlib/expression_tokeniser.go index 0018489b..85e64375 100644 --- a/pkg/yqlib/expression_tokeniser.go +++ b/pkg/yqlib/expression_tokeniser.go @@ -320,7 +320,7 @@ func initLexer() (*lex.Lexer, error) { lexer.Add([]byte("( |\t|\n|\r)+"), skip) lexer.Add([]byte(`\."[^ "]+"\??`), pathToken(true)) - lexer.Add([]byte(`\.[^ \}\{\:\[\],\|\.\[\(\)=]+\??`), pathToken(false)) + lexer.Add([]byte(`\.[^ \}\{\:\[\],\|\.\[\(\)=\n]+\??`), pathToken(false)) lexer.Add([]byte(`\.`), selfToken()) lexer.Add([]byte(`\|`), opToken(pipeOpType)) diff --git a/pkg/yqlib/operator_traverse_path_test.go b/pkg/yqlib/operator_traverse_path_test.go index 9e230915..59fddde3 100644 --- a/pkg/yqlib/operator_traverse_path_test.go +++ b/pkg/yqlib/operator_traverse_path_test.go @@ -35,6 +35,14 @@ var traversePathOperatorScenarios = []expressionScenario{ "D0, P[0 0], (!!int)::1\n", }, }, + { + skipDoc: true, + document: `b: cat`, + expression: ".b\n", + expected: []string{ + "D0, P[b], (!!str)::cat\n", + }, + }, { skipDoc: true, document: `[[[1]]]`,