Skip to content

Commit 07e5b7b

Browse files
committed
add more fuzzing
1 parent fc9f538 commit 07e5b7b

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

card_test.go

+28-1
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,34 @@ func TestCard_FieldValue(t *testing.T) {
397397
}
398398
}
399399

400-
func FuzzCard_FieldValue(f *testing.F) {
400+
// go test -fuzztime=10s -fuzz=Card_FieldValueRaw
401+
func FuzzCard_FieldValueRaw(f *testing.F) {
402+
f.Add(``)
403+
f.Add(`123`)
404+
f.Add(`1,2,3`)
405+
f.Add(`1\abc`) // missing escaping of "\"
406+
f.Add(`1\,2,3`)
407+
f.Add(`1\\,2,3`)
408+
f.Fuzz(func(t *testing.T, raw string) {
409+
fv := FieldValue(raw)
410+
parts := fv.Values()
411+
got1 := NewFieldValue(parts...)
412+
if got1 != fv {
413+
// the raw value was wrongly escaped:
414+
// "got" should now be correctly escaped
415+
if len(got1) <= len(fv) {
416+
t.Errorf("Expected a larger (escaped) string than %q, got %q", fv, got1)
417+
}
418+
// encode again and check that we get back the same (correctly escaped) raw value
419+
got2 := NewFieldValue(got1.Values()...)
420+
if got1 != got2 {
421+
t.Errorf("Expected %q, got %q", got1, got2)
422+
}
423+
}
424+
})
425+
}
426+
427+
func FuzzCard_FieldValueParts(f *testing.F) {
401428
f.Add("p0", "p1")
402429
f.Add("1,2", "3")
403430
f.Add("1\\,2", "3")

0 commit comments

Comments
 (0)