Skip to content

Commit

Permalink
Fix transpiler to allow : in dynamic variables. (#680) (#717)
Browse files Browse the repository at this point in the history
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>
(cherry picked from commit 0560b46)

Co-authored-by: Michel Laterman <82832767+michel-laterman@users.noreply.github.com>
  • Loading branch information
mergify[bot] and michel-laterman authored Jul 13, 2022
1 parent d832255 commit 197ce33
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
- Collects stdout and stderr of applications run as a process and logs them. {issue}[88]
- Remove VerificationMode option to empty string. Default value is `full`. {issue}[184]
- diagnostics collect file mod times are set. {pull}570[570]
- Allow ':' characters in dynamic variables {issue}624[624] {pull}680[680]
- Allow the - char to appear as part of variable names in eql expressions. {issue}709[709] {pull}710[710]

==== New features
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/agent/transpiler/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/elastic/elastic-agent/internal/pkg/core/composable"
)

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

// ErrNoMatch is return when the replace didn't fail, just that no vars match to perform the replace.
var ErrNoMatch = fmt.Errorf("no matching vars")
Expand Down
12 changes: 12 additions & 0 deletions internal/pkg/agent/transpiler/vars_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,24 @@ func TestVars_Replace(t *testing.T) {
false,
false,
},
{
`${"with:colon"}`,
NewStrVal("with:colon"),
false,
false,
},
{
`${"direct"}`,
NewStrVal("direct"),
false,
false,
},
{
`${un-der_score.missing|'with:colon'}`,
NewStrVal("with:colon"),
false,
false,
},
{
`${un-der_score.}`,
NewStrVal(""),
Expand Down

0 comments on commit 197ce33

Please sign in to comment.