Skip to content

Commit e49e588

Browse files
committed
Fixing parsing of escaped characters #2506
1 parent 3894868 commit e49e588

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

pkg/yqlib/lexer_participle.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,12 @@ func stringValue() yqAction {
381381
log.Debug("unwrapped: %v", value)
382382
value = strings.ReplaceAll(value, "\\\"", "\"")
383383
value = strings.ReplaceAll(value, "\\n", "\n")
384+
value = strings.ReplaceAll(value, "\\t", "\t")
385+
value = strings.ReplaceAll(value, "\\r", "\r")
386+
value = strings.ReplaceAll(value, "\\f", "\f")
387+
value = strings.ReplaceAll(value, "\\v", "\v")
388+
value = strings.ReplaceAll(value, "\\b", "\b")
389+
value = strings.ReplaceAll(value, "\\a", "\a")
384390
log.Debug("replaced: %v", value)
385391
return &token{TokenType: operationToken, Operation: &Operation{
386392
OperationType: stringInterpolationOpType,

pkg/yqlib/lexer_participle_test.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,90 @@ var participleLexerScenarios = []participleLexerScenario{
704704
},
705705
},
706706
},
707+
{
708+
expression: `"string with a\r"`,
709+
tokens: []*token{
710+
{
711+
TokenType: operationToken,
712+
Operation: &Operation{
713+
OperationType: stringInterpolationOpType,
714+
Value: "string with a\r",
715+
StringValue: "string with a\r",
716+
Preferences: nil,
717+
},
718+
},
719+
},
720+
},
721+
{
722+
expression: `"string with a\t"`,
723+
tokens: []*token{
724+
{
725+
TokenType: operationToken,
726+
Operation: &Operation{
727+
OperationType: stringInterpolationOpType,
728+
Value: "string with a\t",
729+
StringValue: "string with a\t",
730+
Preferences: nil,
731+
},
732+
},
733+
},
734+
},
735+
{
736+
expression: `"string with a\f"`,
737+
tokens: []*token{
738+
{
739+
TokenType: operationToken,
740+
Operation: &Operation{
741+
OperationType: stringInterpolationOpType,
742+
Value: "string with a\f",
743+
StringValue: "string with a\f",
744+
Preferences: nil,
745+
},
746+
},
747+
},
748+
},
749+
{
750+
expression: `"string with a\v"`,
751+
tokens: []*token{
752+
{
753+
TokenType: operationToken,
754+
Operation: &Operation{
755+
OperationType: stringInterpolationOpType,
756+
Value: "string with a\v",
757+
StringValue: "string with a\v",
758+
Preferences: nil,
759+
},
760+
},
761+
},
762+
},
763+
{
764+
expression: `"string with a\b"`,
765+
tokens: []*token{
766+
{
767+
TokenType: operationToken,
768+
Operation: &Operation{
769+
OperationType: stringInterpolationOpType,
770+
Value: "string with a\b",
771+
StringValue: "string with a\b",
772+
Preferences: nil,
773+
},
774+
},
775+
},
776+
},
777+
{
778+
expression: `"string with a\a"`,
779+
tokens: []*token{
780+
{
781+
TokenType: operationToken,
782+
Operation: &Operation{
783+
OperationType: stringInterpolationOpType,
784+
Value: "string with a\a",
785+
StringValue: "string with a\a",
786+
Preferences: nil,
787+
},
788+
},
789+
},
790+
},
707791
}
708792

709793
func TestParticipleLexer(t *testing.T) {

0 commit comments

Comments
 (0)