Skip to content

Commit 0560b46

Browse files
Fix transpiler to allow : in dynamic variables. (#680)
Fix transpiler regex to allow ':' characters in dynamic variables so that users can input "${dynamic.lookup|'fallback.here'}". Co-authored-by: Aleksandr Maus <aleksandr.maus@elastic.co>
1 parent 28721eb commit 0560b46

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

CHANGELOG.next.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
- Collects stdout and stderr of applications run as a process and logs them. {issue}[88]
108108
- Remove VerificationMode option to empty string. Default value is `full`. {issue}[184]
109109
- diagnostics collect file mod times are set. {pull}570[570]
110+
- Allow ':' characters in dynamic variables {issue}624[624] {pull}680[680]
110111
- Allow the - char to appear as part of variable names in eql expressions. {issue}709[709] {pull}710[710]
111112

112113
==== New features

internal/pkg/agent/transpiler/vars.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/elastic/elastic-agent/internal/pkg/core/composable"
1515
)
1616

17-
var varsRegex = regexp.MustCompile(`\${([\p{L}\d\s\\\-_|.'"]*)}`)
17+
var varsRegex = regexp.MustCompile(`\${([\p{L}\d\s\\\-_|.'":]*)}`)
1818

1919
// ErrNoMatch is return when the replace didn't fail, just that no vars match to perform the replace.
2020
var ErrNoMatch = fmt.Errorf("no matching vars")

internal/pkg/agent/transpiler/vars_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,24 @@ func TestVars_Replace(t *testing.T) {
8181
false,
8282
false,
8383
},
84+
{
85+
`${"with:colon"}`,
86+
NewStrVal("with:colon"),
87+
false,
88+
false,
89+
},
8490
{
8591
`${"direct"}`,
8692
NewStrVal("direct"),
8793
false,
8894
false,
8995
},
96+
{
97+
`${un-der_score.missing|'with:colon'}`,
98+
NewStrVal("with:colon"),
99+
false,
100+
false,
101+
},
90102
{
91103
`${un-der_score.}`,
92104
NewStrVal(""),

0 commit comments

Comments
 (0)