@@ -140,9 +140,7 @@ func CompileHostnamePattern(pattern string) (*regexp.Regexp, error) {
140
140
if strings .Contains (pattern , "http:" ) || strings .Contains (pattern , "https:" ) {
141
141
return nil , xerrors .Errorf ("hostname pattern must not contain a scheme: %q" , pattern )
142
142
}
143
- if strings .Contains (pattern , ":" ) {
144
- return nil , xerrors .Errorf ("hostname pattern must not contain a port: %q" , pattern )
145
- }
143
+
146
144
if strings .HasPrefix (pattern , "." ) || strings .HasSuffix (pattern , "." ) {
147
145
return nil , xerrors .Errorf ("hostname pattern must not start or end with a period: %q" , pattern )
148
146
}
@@ -155,7 +153,17 @@ func CompileHostnamePattern(pattern string) (*regexp.Regexp, error) {
155
153
if ! strings .HasPrefix (pattern , "*" ) {
156
154
return nil , xerrors .Errorf ("hostname pattern must only contain an asterisk at the beginning: %q" , pattern )
157
155
}
158
- for i , label := range strings .Split (pattern , "." ) {
156
+
157
+ // If there is a hostname:port, we only care about the hostname. For hostname
158
+ // pattern reasons, we do not actually care what port the client is requesting.
159
+ // Any port provided here is used for generating urls for the ui, not for
160
+ // validation.
161
+ hostname , _ , err := net .SplitHostPort (pattern )
162
+ if err == nil {
163
+ pattern = hostname
164
+ }
165
+
166
+ for i , label := range strings .Split (hostname , "." ) {
159
167
if i == 0 {
160
168
// We have to allow the asterisk to be a valid hostname label, so
161
169
// we strip the asterisk (which is only on the first one).
0 commit comments