mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-29 02:45:06 +00:00
fix: cache regex globally (#7546)
Signed-off-by: Furkan <furkan.turkal@trendyol.com> Co-authored-by: Emin <emin.aktas@trendyol.com>
This commit is contained in:
parent
9811417022
commit
a21c5fb347
2 changed files with 6 additions and 8 deletions
|
@ -87,13 +87,14 @@ func newFilter(kind, namespace, name string) filter {
|
|||
}
|
||||
}
|
||||
|
||||
var submatchallRegex = regexp.MustCompile(`\[([^\[\]]*)\]`)
|
||||
|
||||
// ParseKinds parses the kinds if a single string contains comma separated kinds
|
||||
// {"1,2,3","4","5"} => {"1","2","3","4","5"}
|
||||
func parseKinds(in string) []filter {
|
||||
resources := []filter{}
|
||||
var resource filter
|
||||
re := regexp.MustCompile(`\[([^\[\]]*)\]`)
|
||||
submatchall := re.FindAllString(in, -1)
|
||||
submatchall := submatchallRegex.FindAllString(in, -1)
|
||||
for _, element := range submatchall {
|
||||
element = strings.Trim(element, "[")
|
||||
element = strings.Trim(element, "]")
|
||||
|
|
|
@ -47,17 +47,14 @@ var (
|
|||
errOperationForbidden = errors.New("variables are forbidden in the path of a JSONPatch")
|
||||
)
|
||||
|
||||
var allowedJsonPatch = regexp.MustCompile("^/")
|
||||
|
||||
// validateJSONPatchPathForForwardSlash checks for forward slash
|
||||
func validateJSONPatchPathForForwardSlash(patch string) error {
|
||||
// Replace all variables in PatchesJSON6902, all variable checks should have happened already.
|
||||
// This prevents further checks from failing unexpectedly.
|
||||
patch = variables.ReplaceAllVars(patch, func(s string) string { return "kyvernojsonpatchvariable" })
|
||||
|
||||
re, err := regexp.Compile("^/")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
jsonPatch, err := yaml.ToJSON([]byte(patch))
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -74,7 +71,7 @@ func validateJSONPatchPathForForwardSlash(patch string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
val := re.MatchString(path)
|
||||
val := allowedJsonPatch.MatchString(path)
|
||||
|
||||
if !val {
|
||||
return fmt.Errorf("%s", path)
|
||||
|
|
Loading…
Add table
Reference in a new issue