Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc770ff2

Browse files
committed
fix: allow ports in wildcard url configuration
This just forwards the port to the ui that generates urls.Our existing parsing + regex already supported ports forsubdomain app requests.
1 parent7e94606 commitc770ff2

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

‎coderd/workspaceapps/appurl/appurl.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,7 @@ func CompileHostnamePattern(pattern string) (*regexp.Regexp, error) {
140140
ifstrings.Contains(pattern,"http:")||strings.Contains(pattern,"https:") {
141141
returnnil,xerrors.Errorf("hostname pattern must not contain a scheme: %q",pattern)
142142
}
143-
ifstrings.Contains(pattern,":") {
144-
returnnil,xerrors.Errorf("hostname pattern must not contain a port: %q",pattern)
145-
}
143+
146144
ifstrings.HasPrefix(pattern,".")||strings.HasSuffix(pattern,".") {
147145
returnnil,xerrors.Errorf("hostname pattern must not start or end with a period: %q",pattern)
148146
}
@@ -155,7 +153,17 @@ func CompileHostnamePattern(pattern string) (*regexp.Regexp, error) {
155153
if!strings.HasPrefix(pattern,"*") {
156154
returnnil,xerrors.Errorf("hostname pattern must only contain an asterisk at the beginning: %q",pattern)
157155
}
158-
fori,label:=rangestrings.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+
iferr==nil {
163+
pattern=hostname
164+
}
165+
166+
fori,label:=rangestrings.Split(hostname,".") {
159167
ifi==0 {
160168
// We have to allow the asterisk to be a valid hostname label, so
161169
// we strip the asterisk (which is only on the first one).

‎coderd/workspaceapps/appurl/appurl_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,6 @@ func TestCompileHostnamePattern(t *testing.T) {
193193
pattern:"https://*.hi.com",
194194
errorContains:"must not contain a scheme",
195195
},
196-
{
197-
name:"Invalid_ContainsPort",
198-
pattern:"*.hi.com:8080",
199-
errorContains:"must not contain a port",
200-
},
201196
{
202197
name:"Invalid_StartPeriod",
203198
pattern:".hi.com",
@@ -249,6 +244,13 @@ func TestCompileHostnamePattern(t *testing.T) {
249244
errorContains:"contains invalid label",
250245
},
251246

247+
{
248+
name:"Valid_ContainsPort",
249+
pattern:"*.hi.com:8080",
250+
// Although a port is provided, the regex already matches any port.
251+
// So it is ignored for validation purposes.
252+
expectedRegex:`([^.]+)\.hi\.com`,
253+
},
252254
{
253255
name:"Valid_Simple",
254256
pattern:"*.hi",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp