Skip to content
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

Panic on Handle /:foo:bar #56

Closed
rogpeppe opened this issue Feb 11, 2015 · 1 comment
Closed

Panic on Handle /:foo:bar #56

rogpeppe opened this issue Feb 11, 2015 · 1 comment
Assignees
Labels

Comments

@rogpeppe
Copy link
Contributor

The following program panics with "slice bounds out of range" error. This
case should be caught and a more understandable message issued instead.

package main

import (
    "github.com/julienschmidt/httprouter"
    "net/http"
)

func main() {
    r := httprouter.New()
    r.Handle("GET", "/:foo:bar/oops", func(http.ResponseWriter, *http.Request, httprouter.Params) {})
}

The panic is as follows:

panic: runtime error: slice bounds out of range

goroutine 1 [running]:
github.com/julienschmidt/httprouter.(*node).insertChild(0xc20805c120, 0x1, 0x6bd190, 0xe, 0x72ea70)
    /home/rog/src/go/src/github.com/julienschmidt/httprouter/tree.go:217 +0x57a
github.com/julienschmidt/httprouter.(*node).addRoute(0xc20805c060, 0x6bd190, 0xe, 0x72ea70)
    /home/rog/src/go/src/github.com/julienschmidt/httprouter/tree.go:184 +0xac
github.com/julienschmidt/httprouter.(*Router).Handle(0xc208030f70, 0x6af1d0, 0x3, 0x6bd190, 0xe, 0x72ea70)
    /home/rog/src/go/src/github.com/julienschmidt/httprouter/router.go:219 +0x1ae
main.main()
    /home/rog/src/tst.go:10 +0x9a
@rogpeppe rogpeppe changed the title Handle panics on /:foo:bar Panic on Handle /:foo:bar Feb 11, 2015
@julienschmidt julienschmidt self-assigned this Feb 11, 2015
@julienschmidt
Copy link
Owner

Even worse: /:foo:bar currently works without panicking at all and the router creates nodes for both :foo:bar and :bar!
I'm working on a fix.

buaazp referenced this issue in buaazp/fasthttprouter Oct 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants