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

Commit4696bf9

Browse files
committed
Export valid name regex
1 parent49084e2 commit4696bf9

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

‎coderd/httpapi/username.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,10 @@ import (
88
)
99

1010
var (
11-
usernameValid=regexp.MustCompile("^[a-zA-Z0-9]+(?:-[a-zA-Z0-9]+)*$")
12-
usernameReplace=regexp.MustCompile("[^a-zA-Z0-9-]*")
11+
UsernameValidRegex=regexp.MustCompile("^[a-zA-Z0-9]+(?:-[a-zA-Z0-9]+)*$")
12+
usernameReplace=regexp.MustCompile("[^a-zA-Z0-9-]*")
1313
)
1414

15-
funcUsernameValidRegexString()string {
16-
returnusernameValid.String()
17-
}
18-
1915
// UsernameValid returns whether the input string is a valid username.
2016
funcUsernameValid(strstring)bool {
2117
iflen(str)>32 {
@@ -24,7 +20,7 @@ func UsernameValid(str string) bool {
2420
iflen(str)<1 {
2521
returnfalse
2622
}
27-
returnusernameValid.MatchString(str)
23+
returnUsernameValidRegex.MatchString(str)
2824
}
2925

3026
// UsernameFrom returns a best-effort username from the provided string.

‎coderd/subdomain.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (api *API) handleSubdomain(middlewares ...func(http.Handler) http.Handler)
7373

7474
var (
7575
// Remove the "starts with" and "ends with" regex components.
76-
nameRegex=strings.Trim(httpapi.UsernameValidRegexString(),"^$")
76+
nameRegex=strings.Trim(httpapi.UsernameValidRegex.String(),"^$")
7777
appURL=regexp.MustCompile(fmt.Sprintf(
7878
// {USERNAME}--{WORKSPACE_NAME}}--{{AGENT_NAME}}--{{PORT}}
7979
`^(?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