Merge pull request #7631 from thaJeztah/strings_cut
replace strings.Split(N) for strings.Cut() or alternatives
This commit is contained in:
@@ -100,9 +100,7 @@ type data struct {
|
||||
func cleanProfileName(profile string) string {
|
||||
// Normally profiles are suffixed by " (enforce)". AppArmor profiles cannot
|
||||
// contain spaces so this doesn't restrict daemon profile names.
|
||||
if parts := strings.SplitN(profile, " ", 2); len(parts) >= 1 {
|
||||
profile = parts[0]
|
||||
}
|
||||
profile, _, _ = strings.Cut(profile, " ")
|
||||
if profile == "" {
|
||||
profile = "unconfined"
|
||||
}
|
||||
@@ -184,17 +182,18 @@ func parseVersion(output string) (int, error) {
|
||||
// Copyright (C) 1999-2008 Novell Inc.
|
||||
// Copyright 2009-2012 Canonical Ltd.
|
||||
|
||||
lines := strings.SplitN(output, "\n", 2)
|
||||
words := strings.Split(lines[0], " ")
|
||||
version := words[len(words)-1]
|
||||
version, _, _ := strings.Cut(output, "\n")
|
||||
if i := strings.LastIndex(version, " "); i >= 0 {
|
||||
version = version[i+1:]
|
||||
}
|
||||
|
||||
// trim "-beta1" suffix from version="3.0.0-beta1" if exists
|
||||
version = strings.SplitN(version, "-", 2)[0]
|
||||
version, _, _ = strings.Cut(version, "-")
|
||||
// also trim tilde
|
||||
version = strings.SplitN(version, "~", 2)[0]
|
||||
version, _, _ = strings.Cut(version, "~")
|
||||
|
||||
// split by major minor version
|
||||
v := strings.Split(version, ".")
|
||||
v := strings.SplitN(version, ".", 4)
|
||||
if len(v) == 0 || len(v) > 3 {
|
||||
return -1, fmt.Errorf("parsing version failed for output: `%s`", output)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user