aboutsummaryrefslogtreecommitdiff
path: root/internal/sexp/fuzz_test.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-09-14 20:10:01 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-09-14 20:10:01 +0200
commitaa24cfb344b1b3eaef7217d996359023cd72ba28 (patch)
treeee0d981d3add58451a83de13ac56be4a8b165eea /internal/sexp/fuzz_test.go
parent00aae60378982902b871a87850e0ed427b28a347 (diff)
downloadkrino-aa24cfb344b1b3eaef7217d996359023cd72ba28.tar.gz
krino-aa24cfb344b1b3eaef7217d996359023cd72ba28.zip
plan 8: fuzz decoders; fold ẞ and invalid UTF-8 correctly, refuse non-UTF-8 paths in krino new
Diffstat (limited to 'internal/sexp/fuzz_test.go')
-rw-r--r--internal/sexp/fuzz_test.go28
1 files changed, 27 insertions, 1 deletions
diff --git a/internal/sexp/fuzz_test.go b/internal/sexp/fuzz_test.go
index 01d436b..c64145a 100644
--- a/internal/sexp/fuzz_test.go
+++ b/internal/sexp/fuzz_test.go
@@ -2,7 +2,10 @@
package sexp
-import "testing"
+import (
+ "testing"
+ "unicode/utf8"
+)
// FuzzParse checks that Parse never panics and that every node it returns
// spans valid bytes, with lists pointing at their own parentheses.
@@ -25,3 +28,26 @@ func FuzzParse(f *testing.F) {
})
})
}
+
+// FuzzQuoteRoundTrip: Quote gives one string atom that parses back to
+// exactly the text quoted, for any valid UTF-8 - quotes, backslashes and
+// newlines included. krino new writes a directory's path into its config
+// with Quote; config files are UTF-8 text, so krino new refuses a path that
+// is not, and invalid UTF-8 is out of this property's scope.
+func FuzzQuoteRoundTrip(f *testing.F) {
+ for _, s := range []string{"plain", `with "quotes"`, `back\slash`, "new\nline", "zażółć", "", "\xff", `\bacme\b`} {
+ f.Add(s)
+ }
+ f.Fuzz(func(t *testing.T, s string) {
+ if !utf8.ValidString(s) {
+ return
+ }
+ nodes, err := Parse("f", []byte(Quote(s)))
+ if err != nil {
+ t.Fatalf("Quote(%q) = %s does not parse: %v", s, Quote(s), err)
+ }
+ if len(nodes) != 1 || nodes[0].Kind != String || nodes[0].Text != s {
+ t.Fatalf("Quote(%q) = %s reads back as %+v", s, Quote(s), nodes)
+ }
+ })
+}