Skip to content

Commit

Permalink
Update KV ignore whitespace before and after = (#2236)
Browse files Browse the repository at this point in the history
* Update KV ignore whitespace before and after `=`

* Update helpers.go

Don't need whitespace infront of KEY

* Add some tests to ensure edge cases

* Ensure quoted and unquoted values act the same
  • Loading branch information
LaurenceJJones authored May 26, 2023
1 parent 6720d89 commit 4fbc340
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions pkg/exprhelpers/exprlib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1399,6 +1399,18 @@ func TestParseKv(t *testing.T) {
expected: map[string]string{"foo": "bar=toto"},
expr: `ParseKV(value, out, "a")`,
},
{
name: "ParseKV() test: empty unquoted string",
value: `foo= bar=toto`,
expected: map[string]string{"bar": "toto", "foo": ""},
expr: `ParseKV(value, out, "a")`,
},
{
name: "ParseKV() test: empty quoted string ",
value: `foo="" bar=toto`,
expected: map[string]string{"bar": "toto", "foo": ""},
expr: `ParseKV(value, out, "a")`,
},
}

for _, tc := range tests {
Expand Down
2 changes: 1 addition & 1 deletion pkg/exprhelpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var dbClient *database.Client

var exprFunctionOptions []expr.Option

var keyValuePattern = regexp.MustCompile(`\s*(?P<key>[^=\s]+)\s*=\s*(?:"(?P<quoted_value>[^"\\]*(?:\\.[^"\\]*)*)"|(?P<value>[^=\s]+))`)
var keyValuePattern = regexp.MustCompile(`(?P<key>[^=\s]+)=(?:"(?P<quoted_value>[^"\\]*(?:\\.[^"\\]*)*)"|(?P<value>[^=\s]+)|\s*)`)

func GetExprOptions(ctx map[string]interface{}) []expr.Option {
ret := []expr.Option{}
Expand Down

0 comments on commit 4fbc340

Please sign in to comment.