stretchr / goweb

A lightweight RESTful web framework for Go
632 stars 61 forks source link

panic with index out of range when call PathPattern.GetPathMatch #81

Closed buzztaiki closed 10 years ago

buzztaiki commented 10 years ago

Sometime, PathPattern.GetPathMatch makes panic.

We reproduce this issue with example code as followings:

package main

import (
        "github.com/stretchr/goweb/paths"
)

func main() {
        p, _ := paths.NewPathPattern("/prefix/static/***")
        p.GetPathMatch(paths.NewPath("/prefix/"))
}

Error:

panic: runtime error: index out of range

goroutine 1 [running]:
runtime.panic(0x51b900, 0x6a6db7)
        /usr/lib/go/src/pkg/runtime/panic.c:266 +0xb6
github.com/stretchr/goweb/paths.(*PathPattern).GetPathMatch(0xc210047060, 0xc2100490c0, 0xc2100490c0)
        /home/taiki/golang/src/github.com/stretchr/goweb/paths/path_pattern.go:122 +0x56a
main.main()
        /home/taiki/golang/a.go:9 +0x6e
exit status 2
matryer commented 10 years ago

Thanks for that @buzztaiki - much appreciated. Next time, instead of writing code as a little program, why not consider just forking the codebase and writing a test that fails (like https://github.com/stretchr/goweb/commit/0575c4b5f23167212696feff627b706eda7f6b9b).

buzztaiki commented 10 years ago

Thanks for your fix! I write a test case next time.