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

Commit49084e2

Browse files
committed
Reuse regex from validation
1 parent82df6f1 commit49084e2

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

‎coderd/httpapi/username.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ var (
1212
usernameReplace=regexp.MustCompile("[^a-zA-Z0-9-]*")
1313
)
1414

15+
funcUsernameValidRegexString()string {
16+
returnusernameValid.String()
17+
}
18+
1519
// UsernameValid returns whether the input string is a valid username.
1620
funcUsernameValid(strstring)bool {
1721
iflen(str)>32 {

‎coderd/subdomain.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"regexp"
77
"strings"
88

9+
"github.com/coder/coder/coderd/httpapi"
10+
911
"github.com/coder/coder/coderd/httpmw"
1012

1113
"github.com/go-chi/chi/v5"
@@ -70,7 +72,8 @@ func (api *API) handleSubdomain(middlewares ...func(http.Handler) http.Handler)
7072
}
7173

7274
var (
73-
nameRegex=`[a-zA-Z0-9]+(?:-[a-zA-Z0-9]+)*`
75+
// Remove the "starts with" and "ends with" regex components.
76+
nameRegex=strings.Trim(httpapi.UsernameValidRegexString(),"^$")
7477
appURL=regexp.MustCompile(fmt.Sprintf(
7578
// {USERNAME}--{WORKSPACE_NAME}}--{{AGENT_NAME}}--{{PORT}}
7679
`^(?P<UserName>%[1]s)--(?P<WorkspaceName>%[1]s)(--(?P<AgentName>%[1]s))?--(?P<AppName>%[1]s)$`,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp