Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't allow profile name to be less than 2 characters #9367

Merged
merged 5 commits into from
Oct 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func runStart(cmd *cobra.Command, args []string) {

if !config.ProfileNameValid(ClusterFlagValue()) {
out.WarningT("Profile name '{{.name}}' is not valid", out.V{"name": ClusterFlagValue()})
exit.Message(reason.Usage, "Only alphanumeric and dashes '-' are permitted. Minimum 1 character, starting with alphanumeric.")
exit.Message(reason.Usage, "Only alphanumeric and dashes '-' are permitted. Minimum 2 characters, starting with alphanumeric.")
}

existing, err := config.Load(ClusterFlagValue())
Expand Down
4 changes: 2 additions & 2 deletions pkg/minikube/config/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ func ProfileNameValid(name string) bool {
const RestrictedNamePattern = `(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])`

var validName = regexp.MustCompile(`^` + RestrictedNamePattern + `$`)

return validName.MatchString(name)
// length needs to be more than 1 character because docker volume #9366
return validName.MatchString(name) && len(name) > 1
}

// ProfileNameInReservedKeywords checks if the profile is an internal keywords
Expand Down
5 changes: 3 additions & 2 deletions pkg/minikube/config/profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,11 @@ func TestProfileNameValid(t *testing.T) {
"pro-file1": true,
"1st-profile": true,
"1st-2nd-3rd-profile": true,
"n": true,
"1": true,
"12567": true,
"111": true,

"1": false,
"n": false,
"pro file": false,
"pro-file-": false,
"-profile": false,
Expand Down