New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: validate workspace name #5647
fix: validate workspace name #5647
Conversation
✅ Deploy Preview for determined-ui canceled.
|
8cc2d3b
to
bb0e7e6
Compare
master/internal/api_workspace.go
Outdated
@@ -281,6 +281,10 @@ func (a *apiServer) PostWorkspace( | |||
return nil, status.Errorf(codes.InvalidArgument, | |||
"name '%s' must be at most 80 character long", req.Name) | |||
} | |||
if len(strings.Trim(req.Name, " ")) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we really want to restrict workspace names this way then we should be accounting for all whitespace characters. There is a unicode utility to do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably something like this should trim both common whitespace and unicode separators:
var whitespaceText = regexp.MustCompile("[\\pZ[:space:]]")
func main() {
s := "Hello, p\tl\naygr ou\u2028n\u00a0d"
fmt.Println(whitespaceText.ReplaceAllLiteralString(s, ""))
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think we just wanna trim leading and trailing whitespaces to accept names like Hello World
or test v1
, so i made it like this
len(strings.TrimFunc(name, unicode.IsSpace)) == 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay, that should work. I did not realize we want to trim these spaces (what if user really wants to have them there). if we do, perhaps we'd want to do the same every time we parse workspace names in other APIs, e.g. in the experiment config on experiment submission.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i see. then beckend just checks if the name isnt whitespace-only, and dont trim whitespace if there are at least 1 non-whitespace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works as described, but do make sure the exact rules we want to follow before merging.
bb0e7e6
to
32b6cc5
Compare
74470b7
to
ab73434
Compare
ab73434
to
7c7c4f2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left minor formatting suggestions but otherwise great work!
Description
WEB-746
Test Plan
Commentary (optional)
Checklist
docs/release-notes/
.See Release Note for details.