Skip to content

Commit 4ad1355

Browse files
elwinarbradfitz
authored andcommitted
html: add a Fuzz function
Adds a sample Fuzz test function to package html based on https://github.com/dvyukov/go-fuzz-corpus/blob/master/stdhtml/main.go Updates #19109 Updates #31309 Change-Id: I8c49fff8f70fc8a8813daf1abf0044752003adbb Reviewed-on: https://go-review.googlesource.com/c/go/+/174301 Reviewed-by: Brad Fitzpatrick <[email protected]> Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 12aec55 commit 4ad1355

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/html/fuzz.go

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2019 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// +build gofuzz
6+
7+
package html
8+
9+
import (
10+
"fmt"
11+
)
12+
13+
func Fuzz(data []byte) int {
14+
v := string(data)
15+
16+
e := EscapeString(v)
17+
u := UnescapeString(e)
18+
if v != u {
19+
fmt.Printf("v = %q\n", v)
20+
fmt.Printf("e = %q\n", e)
21+
fmt.Printf("u = %q\n", u)
22+
panic("not equal")
23+
}
24+
25+
// As per the documentation, this isn't always equal to v, so it makes
26+
// no sense to check for equality. It can still be interesting to find
27+
// panics in it though.
28+
EscapeString(UnescapeString(v))
29+
30+
return 0
31+
}

0 commit comments

Comments
 (0)