diff --git a/libs/structs/structpath/path.go b/libs/structs/structpath/path.go index adf2be51331..cae058b66fe 100644 --- a/libs/structs/structpath/path.go +++ b/libs/structs/structpath/path.go @@ -6,6 +6,7 @@ import ( "regexp" "strconv" "strings" + "sync" ) // baseVarDef matches a path segment of a ${...} reference. It is the grammar of @@ -14,7 +15,9 @@ import ( const baseVarDef = `_*\p{L}+([-_]*[\p{L}\p{N}]+)*` // pureReference matches a string that is a single ${...} reference. -var pureReference = regexp.MustCompile(`^\$\{(` + baseVarDef + `(\.` + baseVarDef + `(\[[0-9]+\])*)*(\[[0-9]+\])*)\}$`) +var pureReference = sync.OnceValue(func() *regexp.Regexp { + return regexp.MustCompile(`^\$\{(` + baseVarDef + `(\.` + baseVarDef + `(\[[0-9]+\])*)*(\[[0-9]+\])*)\}$`) +}) const ( // Encodes wildcard after a dot: foo.* @@ -714,7 +717,7 @@ func isValidField(s string) bool { // PureReferenceToPath returns a PathNode if s is a pure variable reference, otherwise false. // This function is similar to dynvar.PureReferenceToPath but returns a *PathNode instead of dyn.Path. func PureReferenceToPath(s string) (*PathNode, bool) { - m := pureReference.FindStringSubmatch(s) + m := pureReference().FindStringSubmatch(s) if m == nil { return nil, false }