Skip to content

Commit bbc4d6a

Browse files
committed
fix: regex should handle valid usernames
1 parent fb5b947 commit bbc4d6a

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

cli/sharing.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@ func (r *RootCmd) sharing() *serpent.Command {
3535

3636
func (r *RootCmd) shareWorkspace(orgContext *OrganizationContext) *serpent.Command {
3737
var (
38-
client = new(codersdk.Client)
39-
userAndGroupRegex = regexp.MustCompile(`([A-Za-z0-9]+)(?::([A-Za-z0-9]+))?`)
40-
users []string
41-
groups []string
42-
formatter = cliui.NewOutputFormatter(
38+
// Username regex taken from codersdk/name.go
39+
userAndGroupRegex = regexp.MustCompile(`(^[a-zA-Z0-9]+(?:-[a-zA-Z0-9]+)*)+(?::([A-Za-z0-9-]+))?`)
40+
41+
client = new(codersdk.Client)
42+
users []string
43+
groups []string
44+
formatter = cliui.NewOutputFormatter(
4345
cliui.TableFormat(
4446
[]workspaceShareRow{}, []string{"User", "Group", "Role"}),
4547
cliui.JSONFormat(),

0 commit comments

Comments
 (0)