From aa24cfb344b1b3eaef7217d996359023cd72ba28 Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Mon, 14 Sep 2026 20:10:01 +0200 Subject: plan 8: fuzz decoders; fold ẞ and invalid UTF-8 correctly, refuse non-UTF-8 paths in krino new MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/norm/fuzz_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 internal/norm/fuzz_test.go (limited to 'internal/norm/fuzz_test.go') diff --git a/internal/norm/fuzz_test.go b/internal/norm/fuzz_test.go new file mode 100644 index 0000000..fde62a0 --- /dev/null +++ b/internal/norm/fuzz_test.go @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +package norm + +import "testing" + +// FuzzTextIdempotent: normalising text twice changes nothing more than +// normalising it once, under every case and fold setting, and so for names. +// Keywords are normalised at load and text at match time by the same +// functions; a second pass that still changed something would mean the two +// could disagree about what one normalised string is. +func FuzzTextIdempotent(f *testing.F) { + for _, s := range []string{"Spółka Z O.O.", "ẞ straße", "a\u0301", " tabs\tand\nlines ", "\xff", "İstanbul", "Dž", "Æsir Œuvre"} { + f.Add(s) + } + f.Fuzz(func(t *testing.T, s string) { + for _, opt := range [][2]bool{{false, false}, {true, false}, {false, true}, {true, true}} { + once := Text(s, opt[0], opt[1]) + if twice := Text(once, opt[0], opt[1]); twice != once { + t.Fatalf("Text(%q, %v, %v) = %q, again %q", s, opt[0], opt[1], once, twice) + } + } + for _, fold := range []bool{false, true} { + once := Name(s, fold) + if twice := Name(once, fold); twice != once { + t.Fatalf("Name(%q, %v) = %q, again %q", s, fold, once, twice) + } + } + }) +} -- cgit v1.3