-
Notifications
You must be signed in to change notification settings - Fork 6
Closed
Labels
bugSomething isn't workingSomething isn't workinggood first issueGood for newcomersGood for newcomers
Description
Running this code results in panic:
package main
import (
"fmt"
"github.com/sonh/qs"
)
type Query struct {
Tags []string `qs:"tags,comma"`
}
func main() {
encoder := qs.NewEncoder()
values, _ := encoder.Values(&Query{Tags: []string{}})
fmt.Println(values.Encode())
}
Output
panic: runtime error: index out of range [0] with length 0
goroutine 1 [running]:
github.com/sonh/qs.(*listField).formatFnc(0xc00007c080, {0x4a5140?, 0xc000010048?, 0xc000014280?}, 0xc000014290)
/home/pnx/go/pkg/mod/github.com/sonh/qs@v0.6.0/encode_field.go:116 +0x2f5
github.com/sonh/qs.(*encoder).encodeStruct(0xc00009c040, {0x4ab780?, 0xc000010048?, 0x40c7e7?}, 0xc0000921b0, {0x0, 0x0, 0x0})
/home/pnx/go/pkg/mod/github.com/sonh/qs@v0.6.0/encode.go:190 +0x391
github.com/sonh/qs.(*Encoder).Values(0xc00007c020, {0x4a3400?, 0xc000010048?})
/home/pnx/go/pkg/mod/github.com/sonh/qs@v0.6.0/encode.go:94 +0x1f4
main.main()
/home/pnx/code/qs/test.go:16 +0x54
exit status 2
Correct behavior would be to encode the list into a empty string.
sonh
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workinggood first issueGood for newcomersGood for newcomers