Permalink
Browse files

fix #12 - '/' match everything

  • Loading branch information...
1 parent 490ab46 commit f50f2fc683640244f41b42ff8a5702b3ed96ab06 @binku87 binku87 committed with Jun 13, 2012
Showing with 8 additions and 2 deletions.
  1. +1 −1 mux.go
  2. +7 −1 mux_test.go
View
2 mux.go
@@ -207,7 +207,7 @@ func (ph *patHandler) try(path string) (url.Values, bool) {
for i < len(path) {
switch {
case j >= len(ph.pat):
- if ph.pat[len(ph.pat)-1] == '/' {
+ if ph.pat != "/" && len(ph.pat)-1 >= 0 && ph.pat[len(ph.pat)-1] == '/' {
return p, true
}
return nil, false
View
@@ -11,7 +11,13 @@ import (
)
func TestPatMatch(t *testing.T) {
- params, ok := (&patHandler{"/foo/:name", nil}).try("/foo/bar")
+ params, ok := (&patHandler{"/", nil}).try("/")
+ assert.Equal(t, true, ok)
+
+ params, ok = (&patHandler{"/", nil}).try("/wrong_url")
+ assert.Equal(t, false, ok)
+
+ params, ok = (&patHandler{"/foo/:name", nil}).try("/foo/bar")
assert.Equal(t, true, ok)
assert.Equal(t, url.Values{":name": {"bar"}}, params)

0 comments on commit f50f2fc

Please sign in to comment.