Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions libs/structs/structpath/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"regexp"
"strconv"
"strings"
"sync"
)

// baseVarDef matches a path segment of a ${...} reference. It is the grammar of
Expand All @@ -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.*
Expand Down Expand Up @@ -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
}
Expand Down
Loading