Created
January 28, 2022 06:36
-
-
Save percybolmer/65574adc145cfa7c4084cd5db833b247 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//go:build go1.18 | |
// +build go1.18 | |
package fuzz | |
import ( | |
"net/url" | |
"reflect" | |
"testing" | |
) | |
func FuzzParseQuery(f *testing.F) { | |
f.Add("x=1&y=2") | |
f.Fuzz(func(t *testing.T, queryStr string) { | |
query, err := url.ParseQuery(queryStr) | |
if err != nil { | |
t.Skip() | |
} | |
queryStr2 := query.Encode() | |
query2, err := url.ParseQuery(queryStr2) | |
if err != nil { | |
t.Fatalf("ParseQuery failed to decode a valid encoded query %s: %v", queryStr2, err) | |
} | |
if !reflect.DeepEqual(query, query2) { | |
t.Errorf("ParseQuery gave different query after being encoded\nbefore: %v\nafter: %v", query, query2) | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment