Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions pkg/yqlib/operator_strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,14 @@ func interpolate(d *dataTreeNavigator, context Context, str string) (string, err
i++
continue
case '\\':
// skip the escaped backslash
i++
// A backslash pair is only an interpolation escape when it
// guards an opening paren ("\\(" -> literal "\("). The lexer
// (processEscapeCharacters) has already decoded string escapes,
// so a standalone pair must pass through unchanged rather than
// be halved a second time (#2561).
if i+2 < len(runes) && runes[i+2] == '(' {
i++ // skip the second backslash; '(' is emitted as literal text next
}
default:
log.Debugf("Ignoring non-escaping backslash @ %v[%d]", str, i)
}
Expand Down
16 changes: 16 additions & 0 deletions pkg/yqlib/operator_strings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ var stringsOperatorScenarios = []expressionScenario{
"D0, P[], (!!str)::\\\n",
},
},
{
skipDoc: true,
description: "Interpolation - backslashes are not halved (#2561)",
expression: `"\\\\"`,
expected: []string{
"D0, P[], (!!str)::\\\\\n",
},
},
{
skipDoc: true,
description: "Interpolation - odd backslash run preserved (#2561)",
expression: `"\\\\\\"`,
expected: []string{
"D0, P[], (!!str)::\\\\\\\n",
},
},
{
skipDoc: true,
description: "Interpolation - nested",
Expand Down
Loading