Skip to content

Commit

Permalink
enforce handler patterns to start with /
Browse files Browse the repository at this point in the history
  • Loading branch information
topi314 committed Jul 7, 2023
1 parent b331ced commit 8f83c45
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions handler/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (r *Mux) Autocomplete(pattern string, h AutocompleteHandler) {

// Component registers the given ComponentHandler to the current Router.
func (r *Mux) Component(pattern string, h ComponentHandler) {
checkPatternEmpty(pattern)
checkPattern(pattern)
r.handle(&handlerHolder[ComponentHandler]{
pattern: pattern,
handler: h,
Expand All @@ -176,7 +176,7 @@ func (r *Mux) Component(pattern string, h ComponentHandler) {

// Modal registers the given ModalHandler to the current Router.
func (r *Mux) Modal(pattern string, h ModalHandler) {
checkPatternEmpty(pattern)
checkPattern(pattern)
r.handle(&handlerHolder[ModalHandler]{
pattern: pattern,
handler: h,
Expand All @@ -190,14 +190,10 @@ func (r *Mux) NotFound(h NotFoundHandler) {
r.notFoundHandler = h
}

func checkPatternEmpty(pattern string) {
if pattern == "" {
func checkPattern(pattern string) {
if len(pattern) == 0 {
panic("pattern must not be empty")
}
}

func checkPattern(pattern string) {
checkPatternEmpty(pattern)
if pattern[0] != '/' {
panic("pattern must start with /")
}
Expand Down

0 comments on commit 8f83c45

Please sign in to comment.