mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
Merge pull request #82928 from chendotjs/simplify-regex
simplify regexp with raw string
This commit is contained in:
commit
05588f769d
@ -32,9 +32,9 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
//e.g. framework.ConformanceIt("should provide secure master service ", func() {
|
//e.g. framework.ConformanceIt("should provide secure master service ", func() {
|
||||||
patternStartConformance = "framework.ConformanceIt\\(.*, func\\(\\) {$"
|
patternStartConformance = `framework.ConformanceIt\(.*, func\(\) {$`
|
||||||
patternEndConformance = "}\\)$"
|
patternEndConformance = `}\)$`
|
||||||
patternSkip = "framework.Skip.*\\("
|
patternSkip = `framework.Skip.*\(`
|
||||||
)
|
)
|
||||||
|
|
||||||
// This function checks the requirement: it works for all providers (e.g., no SkipIfProviderIs/SkipUnlessProviderIs calls)
|
// This function checks the requirement: it works for all providers (e.g., no SkipIfProviderIs/SkipUnlessProviderIs calls)
|
||||||
@ -82,7 +82,7 @@ func checkAllProviders(e2eFile string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func processFile(e2ePath string) error {
|
func processFile(e2ePath string) error {
|
||||||
regGoFile := regexp.MustCompile(".*\\.go")
|
regGoFile := regexp.MustCompile(`.*\.go`)
|
||||||
|
|
||||||
files, err := ioutil.ReadDir(e2ePath)
|
files, err := ioutil.ReadDir(e2ePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -36,7 +36,7 @@ import (
|
|||||||
utilprinters "k8s.io/kubectl/pkg/util/printers"
|
utilprinters "k8s.io/kubectl/pkg/util/printers"
|
||||||
)
|
)
|
||||||
|
|
||||||
var jsonRegexp = regexp.MustCompile("^\\{\\.?([^{}]+)\\}$|^\\.?([^{}]+)$")
|
var jsonRegexp = regexp.MustCompile(`^\{\.?([^{}]+)\}$|^\.?([^{}]+)$`)
|
||||||
|
|
||||||
// RelaxedJSONPathExpression attempts to be flexible with JSONPath expressions, it accepts:
|
// RelaxedJSONPathExpression attempts to be flexible with JSONPath expressions, it accepts:
|
||||||
// * metadata.name (no leading '.' or curly braces '{...}'
|
// * metadata.name (no leading '.' or curly braces '{...}'
|
||||||
|
@ -110,7 +110,7 @@ func getEbtablesVersionString(exec utilexec.Interface) (string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
versionMatcher := regexp.MustCompile("v([0-9]+\\.[0-9]+\\.[0-9]+)")
|
versionMatcher := regexp.MustCompile(`v([0-9]+\.[0-9]+\.[0-9]+)`)
|
||||||
match := versionMatcher.FindStringSubmatch(string(bytes))
|
match := versionMatcher.FindStringSubmatch(string(bytes))
|
||||||
if match == nil {
|
if match == nil {
|
||||||
return "", fmt.Errorf("no ebtables version found in string: %s", bytes)
|
return "", fmt.Errorf("no ebtables version found in string: %s", bytes)
|
||||||
|
@ -573,6 +573,8 @@ func makeFullArgs(table Table, chain Chain, args ...string) []string {
|
|||||||
return append([]string{string(chain), "-t", string(table)}, args...)
|
return append([]string{string(chain), "-t", string(table)}, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const iptablesVersionPattern = `v([0-9]+(\.[0-9]+)+)`
|
||||||
|
|
||||||
// getIPTablesVersion runs "iptables --version" and parses the returned version
|
// getIPTablesVersion runs "iptables --version" and parses the returned version
|
||||||
func getIPTablesVersion(exec utilexec.Interface, protocol Protocol) (*utilversion.Version, error) {
|
func getIPTablesVersion(exec utilexec.Interface, protocol Protocol) (*utilversion.Version, error) {
|
||||||
// this doesn't access mutable state so we don't need to use the interface / runner
|
// this doesn't access mutable state so we don't need to use the interface / runner
|
||||||
@ -581,7 +583,7 @@ func getIPTablesVersion(exec utilexec.Interface, protocol Protocol) (*utilversio
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
versionMatcher := regexp.MustCompile("v([0-9]+(\\.[0-9]+)+)")
|
versionMatcher := regexp.MustCompile(iptablesVersionPattern)
|
||||||
match := versionMatcher.FindStringSubmatch(string(bytes))
|
match := versionMatcher.FindStringSubmatch(string(bytes))
|
||||||
if match == nil {
|
if match == nil {
|
||||||
return nil, fmt.Errorf("no iptables version found in string: %s", bytes)
|
return nil, fmt.Errorf("no iptables version found in string: %s", bytes)
|
||||||
@ -641,7 +643,7 @@ func getIPTablesRestoreVersionString(exec utilexec.Interface, protocol Protocol)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
versionMatcher := regexp.MustCompile("v([0-9]+(\\.[0-9]+)+)")
|
versionMatcher := regexp.MustCompile(iptablesVersionPattern)
|
||||||
match := versionMatcher.FindStringSubmatch(string(bytes))
|
match := versionMatcher.FindStringSubmatch(string(bytes))
|
||||||
if match == nil {
|
if match == nil {
|
||||||
return "", fmt.Errorf("no iptables version found in string: %s", bytes)
|
return "", fmt.Errorf("no iptables version found in string: %s", bytes)
|
||||||
|
Loading…
Reference in New Issue
Block a user