Catching a potential panic in strval parsing

Signed-off-by: Matt Farina <matt@mattfarina.com>
pull/8141/head
Matt Farina 5 years ago
parent 8f1f0e0db2
commit 6857da251e
No known key found for this signature in database
GPG Key ID: 9436E80BFBA46909

@ -150,7 +150,12 @@ func runeSet(r []rune) map[rune]bool {
return s
}
func (t *parser) key(data map[string]interface{}) error {
func (t *parser) key(data map[string]interface{}) (reterr error) {
defer func() {
if r := recover(); r != nil {
reterr = fmt.Errorf("unable to parse key: %s", r)
}
}()
stop := runeSet([]rune{'=', '[', ',', '.'})
for {
switch k, last, err := runesUntil(t.sc, stop); {

@ -362,6 +362,10 @@ func TestParseSet(t *testing.T) {
},
},
},
{
str: "]={}].",
err: true,
},
}
for _, tt := range tests {

Loading…
Cancel
Save