@@ -3,6 +3,7 @@ package cmd
3
3
import (
4
4
"fmt"
5
5
"io"
6
+ "regexp"
6
7
"strconv"
7
8
"strings"
8
9
@@ -44,6 +45,9 @@ const (
44
45
// and no Dockerfile is detected in the repository.
45
46
var ErrNoDockerfileDetected = fmt .Errorf ("No Dockerfile was found in the repository and the requested build strategy is 'docker'" )
46
47
48
+ // the opposite of kvalidation.DNS1123LabelFmt
49
+ var invalidNameCharactersRegexp = regexp .MustCompile ("[^-a-z0-9]" )
50
+
47
51
// AppConfig contains all the necessary configuration for an application
48
52
type AppConfig struct {
49
53
SourceRepositories util.StringList
@@ -587,14 +591,21 @@ func ensureValidUniqueName(names map[string]int, name string) (string, error) {
587
591
if len (name ) < 2 {
588
592
return "" , fmt .Errorf ("invalid name: %s" , name )
589
593
}
594
+
595
+ // Make all names lowercase
596
+ name = strings .ToLower (name )
597
+
598
+ // Remove everything except [-0-9a-z]
599
+ name = invalidNameCharactersRegexp .ReplaceAllString (name , "" )
600
+
601
+ // Remove leading hyphen(s) that may be introduced by the previous step
602
+ name = strings .TrimLeft (name , "-" )
603
+
590
604
if len (name ) > kvalidation .DNS1123SubdomainMaxLength {
591
605
glog .V (4 ).Infof ("Trimming %s to maximum allowable length (%d)\n " , name , kvalidation .DNS1123SubdomainMaxLength )
592
606
name = name [:kvalidation .DNS1123SubdomainMaxLength ]
593
607
}
594
608
595
- // Make all names lowercase
596
- name = strings .ToLower (name )
597
-
598
609
count , existing := names [name ]
599
610
if ! existing {
600
611
names [name ] = 0
0 commit comments