Merge pull request #82928 from chendotjs/simplify-regex

simplify regexp with raw string
This commit is contained in:
Kubernetes Prow Robot 2019-09-25 11:07:02 -07:00 committed by GitHub
commit 05588f769d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 8 deletions

View File

@ -32,9 +32,9 @@ import (
const (
//e.g. framework.ConformanceIt("should provide secure master service ", func() {
patternStartConformance = "framework.ConformanceIt\\(.*, func\\(\\) {$"
patternEndConformance = "}\\)$"
patternSkip = "framework.Skip.*\\("
patternStartConformance = `framework.ConformanceIt\(.*, func\(\) {$`
patternEndConformance = `}\)$`
patternSkip = `framework.Skip.*\(`
)
// 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 {
regGoFile := regexp.MustCompile(".*\\.go")
regGoFile := regexp.MustCompile(`.*\.go`)
files, err := ioutil.ReadDir(e2ePath)
if err != nil {

View File

@ -36,7 +36,7 @@ import (
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:
// * metadata.name (no leading '.' or curly braces '{...}'

View File

@ -110,7 +110,7 @@ func getEbtablesVersionString(exec utilexec.Interface) (string, error) {
if err != nil {
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))
if match == nil {
return "", fmt.Errorf("no ebtables version found in string: %s", bytes)

View File

@ -573,6 +573,8 @@ func makeFullArgs(table Table, chain Chain, args ...string) []string {
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
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
@ -581,7 +583,7 @@ func getIPTablesVersion(exec utilexec.Interface, protocol Protocol) (*utilversio
if err != nil {
return nil, err
}
versionMatcher := regexp.MustCompile("v([0-9]+(\\.[0-9]+)+)")
versionMatcher := regexp.MustCompile(iptablesVersionPattern)
match := versionMatcher.FindStringSubmatch(string(bytes))
if match == nil {
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 {
return "", err
}
versionMatcher := regexp.MustCompile("v([0-9]+(\\.[0-9]+)+)")
versionMatcher := regexp.MustCompile(iptablesVersionPattern)
match := versionMatcher.FindStringSubmatch(string(bytes))
if match == nil {
return "", fmt.Errorf("no iptables version found in string: %s", bytes)