akamensky / argparse

Argparse for golang. Just because `flag` sucks
MIT License
611 stars 62 forks source link

panic: runtime error: slice bounds out of range #9

Closed Programmerino closed 6 years ago

Programmerino commented 6 years ago

If you use an argument and pass no value, the go program panics with panic: runtime error: slice bounds out of range. PoC:

parser := argparse.NewParser("download", "Downloads URL matching provided string")
// Create string flag
searchQuery = parser.String("q", "query", &argparse.Options{Required: true, Help: "URL to download"})
// Parse input
err := parser.Parse(os.Args)
if err != nil {
    // In case of error print error and print usage
    // This can also be done by passing -h or --help flags
    fmt.Println(err.Error())
    fmt.Print(parser.Usage(parser))
}
go run main.go -q
akamensky commented 6 years ago

Right on, seems I missed the array boundaries check there. Should be an easy fix

akamensky commented 6 years ago

@SkyrisBactera Added the fix for this issue along with test case. Closing. Feel free to re-open if you feel the issue is not yet resolved