Skip to content

Commit

Permalink
chore(placeholders): refactor matching capture and add regression test
Browse files Browse the repository at this point in the history
  • Loading branch information
astromechza committed Jul 9, 2024
1 parent 00d7027 commit 4bbf5df
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions framework/substitution.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

var (
// placeholderRegEx will search for ${...} with any sequence of characters between them.
placeholderRegEx = regexp.MustCompile(`\$(\$|{([^}]*)})`)
placeholderRegEx = regexp.MustCompile(`\$((?:\$?{([^}]*)})|\$)`)
)

func SplitRefParts(ref string) []string {
Expand Down Expand Up @@ -52,7 +52,7 @@ func SubstituteString(src string, inner func(string) (string, error)) (string, e
}

// support escaped dollars
if matches[1] == "$" {
if strings.HasPrefix(matches[1], "$") {
return matches[1]
}

Expand Down
3 changes: 3 additions & 0 deletions framework/substitution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ func TestSubstituteString(t *testing.T) {
{Input: "$abc", Expected: "$abc"},
{Input: "abc $$ abc", Expected: "abc $ abc"},
{Input: "$${abc}", Expected: "${abc}"},
{Input: "$$${abc}", ExpectedError: "invalid ref 'abc': unknown reference root, use $$ to escape the substitution"},
{Input: "$$$${abc}", Expected: "$${abc}"},
{Input: "$$$$${abc}", ExpectedError: "invalid ref 'abc': unknown reference root, use $$ to escape the substitution"},
{Input: "$${abc .4t3298y *(^&(*}", Expected: "${abc .4t3298y *(^&(*}"},
{Input: "my name is ${metadata.name}", Expected: "my name is test-name"},
{Input: "my name is ${metadata.thing\\.two}", ExpectedError: "invalid ref 'metadata.thing\\.two': key 'thing.two' not found"},
Expand Down

0 comments on commit 4bbf5df

Please sign in to comment.