Fixing parsing of escaped characters #2506

This commit is contained in:
Mike Farah 2025-11-16 09:12:13 +11:00
parent 389486829d
commit e49e588ab5
2 changed files with 90 additions and 0 deletions

View File

@ -381,6 +381,12 @@ func stringValue() yqAction {
log.Debug("unwrapped: %v", value)
value = strings.ReplaceAll(value, "\\\"", "\"")
value = strings.ReplaceAll(value, "\\n", "\n")
value = strings.ReplaceAll(value, "\\t", "\t")
value = strings.ReplaceAll(value, "\\r", "\r")
value = strings.ReplaceAll(value, "\\f", "\f")
value = strings.ReplaceAll(value, "\\v", "\v")
value = strings.ReplaceAll(value, "\\b", "\b")
value = strings.ReplaceAll(value, "\\a", "\a")
log.Debug("replaced: %v", value)
return &token{TokenType: operationToken, Operation: &Operation{
OperationType: stringInterpolationOpType,

View File

@ -704,6 +704,90 @@ var participleLexerScenarios = []participleLexerScenario{
},
},
},
{
expression: `"string with a\r"`,
tokens: []*token{
{
TokenType: operationToken,
Operation: &Operation{
OperationType: stringInterpolationOpType,
Value: "string with a\r",
StringValue: "string with a\r",
Preferences: nil,
},
},
},
},
{
expression: `"string with a\t"`,
tokens: []*token{
{
TokenType: operationToken,
Operation: &Operation{
OperationType: stringInterpolationOpType,
Value: "string with a\t",
StringValue: "string with a\t",
Preferences: nil,
},
},
},
},
{
expression: `"string with a\f"`,
tokens: []*token{
{
TokenType: operationToken,
Operation: &Operation{
OperationType: stringInterpolationOpType,
Value: "string with a\f",
StringValue: "string with a\f",
Preferences: nil,
},
},
},
},
{
expression: `"string with a\v"`,
tokens: []*token{
{
TokenType: operationToken,
Operation: &Operation{
OperationType: stringInterpolationOpType,
Value: "string with a\v",
StringValue: "string with a\v",
Preferences: nil,
},
},
},
},
{
expression: `"string with a\b"`,
tokens: []*token{
{
TokenType: operationToken,
Operation: &Operation{
OperationType: stringInterpolationOpType,
Value: "string with a\b",
StringValue: "string with a\b",
Preferences: nil,
},
},
},
},
{
expression: `"string with a\a"`,
tokens: []*token{
{
TokenType: operationToken,
Operation: &Operation{
OperationType: stringInterpolationOpType,
Value: "string with a\a",
StringValue: "string with a\a",
Preferences: nil,
},
},
},
},
}
func TestParticipleLexer(t *testing.T) {