Perform checks for / and * inside a newPath func.
This commit is contained in:
parent
5d7d595df3
commit
99a7cebd0a
14
httpr.go
14
httpr.go
@ -9,13 +9,21 @@ import (
|
||||
|
||||
type path []string
|
||||
|
||||
// newPath splits a path and ensures that it starts with a slash (/).
|
||||
// newPath splits a path and ensures that it starts with a slash (/) and doesn't
|
||||
// have more than 1 catch-all parameter.
|
||||
func newPath(path string) (path, error) {
|
||||
parts := strings.Split(strings.TrimSuffix(path, "/"), "/")
|
||||
if parts[0] != "" {
|
||||
if path[0] != '/' {
|
||||
return nil, errors.New("path should start with a slash (/) symbol")
|
||||
}
|
||||
|
||||
if strings.Count(path, "*") > 1 {
|
||||
return nil, errors.New("there can be only one catch-all (*) parameter in path")
|
||||
}
|
||||
|
||||
parts := strings.Split(strings.TrimSuffix(path, "/"), "/")
|
||||
|
||||
parts[0] = "/"
|
||||
|
||||
return parts, nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user