From acadce6af3e8f399ca0afac25a0a79fe0d4addaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charles-Edouard=20Br=C3=A9t=C3=A9ch=C3=A9?= Date: Tue, 20 Feb 2024 21:03:59 +0100 Subject: [PATCH] fix: concurrency issue when parsing expression (#312) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Charles-Edouard Brétéché --- pkg/engine/template/template.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pkg/engine/template/template.go b/pkg/engine/template/template.go index 8b785eb4..091d858e 100644 --- a/pkg/engine/template/template.go +++ b/pkg/engine/template/template.go @@ -11,10 +11,7 @@ import ( "github.com/jmespath-community/go-jmespath/pkg/parsing" ) -var ( - variable = regexp.MustCompile(`{{(.*?)}}`) - parser = parsing.NewParser() -) +var variable = regexp.MustCompile(`{{(.*?)}}`) func String(ctx context.Context, in string, value any, bindings binding.Bindings, opts ...Option) string { groups := variable.FindAllStringSubmatch(in, -1) @@ -37,6 +34,7 @@ func String(ctx context.Context, in string, value any, bindings binding.Bindings func Execute(ctx context.Context, statement string, value any, bindings binding.Bindings, opts ...Option) (any, error) { o := buildOptions(opts...) vm := interpreter.NewInterpreter(nil, bindings) + parser := parsing.NewParser() compiled, err := parser.Parse(statement) if err != nil { return nil, err