diff --git a/common/libnetwork/resolvconf/resolvconf.go b/common/libnetwork/resolvconf/resolvconf.go index 782ad79868..6b844373d9 100644 --- a/common/libnetwork/resolvconf/resolvconf.go +++ b/common/libnetwork/resolvconf/resolvconf.go @@ -5,9 +5,9 @@ package resolvconf import ( "bytes" "os" - "regexp" "strings" + "github.com/containers/storage/pkg/regexp" "github.com/sirupsen/logrus" ) @@ -32,11 +32,11 @@ var ( // ipLocalhost is a regex pattern for IPv4 or IPv6 loopback range. ipLocalhost = `((127\.([0-9]{1,3}\.){2}[0-9]{1,3})|(::1)$)` - localhostNSRegexp = regexp.MustCompile(`(?m)^nameserver\s+` + ipLocalhost + `\s*\n*`) - nsIPv6Regexp = regexp.MustCompile(`(?m)^nameserver\s+` + ipv6Address + `\s*\n*`) - nsRegexp = regexp.MustCompile(`^\s*nameserver\s*((` + ipv4Address + `)|(` + ipv6Address + `))\s*$`) - searchRegexp = regexp.MustCompile(`^\s*search\s*(([^\s]+\s*)*)$`) - optionsRegexp = regexp.MustCompile(`^\s*options\s*(([^\s]+\s*)*)$`) + localhostNSRegexp = regexp.Delayed(`(?m)^nameserver\s+` + ipLocalhost + `\s*\n*`) + nsIPv6Regexp = regexp.Delayed(`(?m)^nameserver\s+` + ipv6Address + `\s*\n*`) + nsRegexp = regexp.Delayed(`^\s*nameserver\s*((` + ipv4Address + `)|(` + ipv6Address + `))\s*$`) + searchRegexp = regexp.Delayed(`^\s*search\s*(([^\s]+\s*)*)$`) + optionsRegexp = regexp.Delayed(`^\s*options\s*(([^\s]+\s*)*)$`) ) // filterResolvDNS cleans up the config in resolvConf. It has two main jobs: diff --git a/common/pkg/configmaps/configmaps.go b/common/pkg/configmaps/configmaps.go index bc78fb17bf..8a6bc8e5a0 100644 --- a/common/pkg/configmaps/configmaps.go +++ b/common/pkg/configmaps/configmaps.go @@ -5,12 +5,12 @@ import ( "fmt" "os" "path/filepath" - "regexp" "strings" "time" "github.com/containers/common/pkg/configmaps/filedriver" "github.com/containers/storage/pkg/lockfile" + "github.com/containers/storage/pkg/regexp" "github.com/containers/storage/pkg/stringid" ) @@ -49,7 +49,7 @@ var configMapsFile = "configmaps.json" // configMapNameRegexp matches valid configMap names // Allowed: 64 [a-zA-Z0-9-_.] characters, and the start and end character must be [a-zA-Z0-9] -var configMapNameRegexp = regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`) +var configMapNameRegexp = regexp.Delayed(`^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`) // ConfigMapManager holds information on handling configmaps type ConfigMapManager struct { diff --git a/common/pkg/report/template.go b/common/pkg/report/template.go index e390ea3225..d9b942ba48 100644 --- a/common/pkg/report/template.go +++ b/common/pkg/report/template.go @@ -4,11 +4,11 @@ import ( "bytes" "encoding/json" "reflect" - "regexp" "strings" "text/template" "github.com/containers/common/pkg/report/camelcase" + "github.com/containers/storage/pkg/regexp" ) // Template embeds template.Template to add functionality to methods @@ -160,7 +160,7 @@ func (t *Template) IsTable() bool { return t.isTable } -var rangeRegex = regexp.MustCompile(`(?s){{\s*range\s*\.\s*}}.*{{\s*end\s*-?\s*}}`) +var rangeRegex = regexp.Delayed(`(?s){{\s*range\s*\.\s*}}.*{{\s*end\s*-?\s*}}`) // EnforceRange ensures that the format string contains a range func EnforceRange(format string) string { diff --git a/common/pkg/report/validate.go b/common/pkg/report/validate.go index 8d6cff246a..bdecf7796b 100644 --- a/common/pkg/report/validate.go +++ b/common/pkg/report/validate.go @@ -1,12 +1,12 @@ package report import ( - "regexp" + "github.com/containers/storage/pkg/regexp" ) // Check for json, {{json }} and {{ json. }} which are not valid go template, // {{json .}} is valid and thus not matched to let the template handle it like docker does. -var jsonRegex = regexp.MustCompile(`^\s*(json|{{\s*json\.?\s*}})\s*$`) +var jsonRegex = regexp.Delayed(`^\s*(json|{{\s*json\.?\s*}})\s*$`) // JSONFormat test CLI --format string to be a JSON request // diff --git a/common/pkg/secrets/secrets.go b/common/pkg/secrets/secrets.go index 7797f0fc59..d90775fa6f 100644 --- a/common/pkg/secrets/secrets.go +++ b/common/pkg/secrets/secrets.go @@ -5,7 +5,6 @@ import ( "fmt" "os" "path/filepath" - "regexp" "strings" "time" @@ -13,6 +12,7 @@ import ( "github.com/containers/common/pkg/secrets/passdriver" "github.com/containers/common/pkg/secrets/shelldriver" "github.com/containers/storage/pkg/lockfile" + "github.com/containers/storage/pkg/regexp" "github.com/containers/storage/pkg/stringid" ) @@ -51,7 +51,7 @@ var secretsFile = "secrets.json" // secretNameRegexp matches valid secret names // Allowed: 64 [a-zA-Z0-9-_.] characters, and the start and end character must be [a-zA-Z0-9] -var secretNameRegexp = regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`) +var secretNameRegexp = regexp.Delayed(`^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`) // SecretsManager holds information on handling secrets //