Skip to content

Commit

Permalink
Skip and warn when interpolating strings and theres a unclosed bracket
Browse files Browse the repository at this point in the history
  • Loading branch information
mikefarah committed Jun 29, 2024
1 parent 0b7d4b7 commit 28646c7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
3 changes: 2 additions & 1 deletion pkg/yqlib/operator_strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ func interpolate(d *dataTreeNavigator, context Context, str string) (string, err
}
}
if inExpression {
return "", fmt.Errorf("unclosed interpolation string \\(")
log.Warning("unclosed interpolation string, skipping interpolation")
return str, nil
}
return sb.String(), nil
}
Expand Down
28 changes: 16 additions & 12 deletions pkg/yqlib/operator_strings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,22 @@ var stringsOperatorScenarios = []expressionScenario{
},
},
{
skipDoc: true,
description: "Interpolation - unclosed interpolation string",
document: `value: things`,
expression: `"Hi \("`,
expectedError: "unclosed interpolation string \\(",
},
{
skipDoc: true,
description: "Interpolation - unclosed interpolation string due to escape",
document: `value: things`,
expression: `"Hi \(\)"`,
expectedError: "unclosed interpolation string \\(",
skipDoc: true,
description: "Interpolation - unclosed interpolation string",
document: `value: things`,
expression: `"Hi \("`,
expected: []string{
"D0, P[], (!!str)::Hi \\(\n",
},
},
{
skipDoc: true,
description: "Interpolation - unclosed interpolation string due to escape",
document: `value: things`,
expression: `"Hi \(\)"`,
expected: []string{
"D0, P[], (!!str)::Hi \\(\\)\n",
},
},
{
description: "To up (upper) case",
Expand Down

0 comments on commit 28646c7

Please sign in to comment.