Skip to content

Commit 8f83c45

Browse files
committed
enforce handler patterns to start with /
1 parent b331ced commit 8f83c45

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

handler/mux.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func (r *Mux) Autocomplete(pattern string, h AutocompleteHandler) {
166166

167167
// Component registers the given ComponentHandler to the current Router.
168168
func (r *Mux) Component(pattern string, h ComponentHandler) {
169-
checkPatternEmpty(pattern)
169+
checkPattern(pattern)
170170
r.handle(&handlerHolder[ComponentHandler]{
171171
pattern: pattern,
172172
handler: h,
@@ -176,7 +176,7 @@ func (r *Mux) Component(pattern string, h ComponentHandler) {
176176

177177
// Modal registers the given ModalHandler to the current Router.
178178
func (r *Mux) Modal(pattern string, h ModalHandler) {
179-
checkPatternEmpty(pattern)
179+
checkPattern(pattern)
180180
r.handle(&handlerHolder[ModalHandler]{
181181
pattern: pattern,
182182
handler: h,
@@ -190,14 +190,10 @@ func (r *Mux) NotFound(h NotFoundHandler) {
190190
r.notFoundHandler = h
191191
}
192192

193-
func checkPatternEmpty(pattern string) {
194-
if pattern == "" {
193+
func checkPattern(pattern string) {
194+
if len(pattern) == 0 {
195195
panic("pattern must not be empty")
196196
}
197-
}
198-
199-
func checkPattern(pattern string) {
200-
checkPatternEmpty(pattern)
201197
if pattern[0] != '/' {
202198
panic("pattern must start with /")
203199
}

0 commit comments

Comments
 (0)