etree
etree copied to clipboard
CompilePath panics when it should return an error
Hello!
Trying your library, I ran into this situation - CompilePath function panics when it should return an error. Perhaps I am doing something wrong? Please, help!
xmlDocument := etree.NewDocument()
xmlDocument.ReadFromString(xml)
path, err := etree.CompilePath("/][") // <- Wrong query here
if err != nil {
fmt.Println(err)
return
}
root := xmlDocument.FindElementsPath(path)
Output:
panic: runtime error: index out of range [-1]
goroutine 1 [running]:
github.com/beevik/etree.(*compiler).parseSegment(0xc000068e98, 0x4dd524, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0)
/tmp/gopath622730673/pkg/mod/github.com/beevik/[email protected]/path.go:258 +0x2d7
github.com/beevik/etree.(*compiler).parsePath(0xc000068e98, 0x4dd523, 0x3, 0x5ba000, 0x0, 0x590)
/tmp/gopath622730673/pkg/mod/github.com/beevik/[email protected]/path.go:226 +0x165
github.com/beevik/etree.CompilePath(0x4dd523, 0x3, 0x590, 0x0, 0x0, 0x4b19f1, 0x4c4360)
/tmp/gopath622730673/pkg/mod/github.com/beevik/[email protected]/path.go:99 +0x4b
main.main()
/tmp/sandbox091201306/prog.go:50 +0x70
Code example - https://play.golang.org/p/kO5V_6Q_mCk