]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
parser/pageparser: Add a parser fuzz test
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 7 Apr 2026 19:44:38 +0000 (21:44 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 9 Apr 2026 10:25:19 +0000 (12:25 +0200)
 Ran it for 40 minutes on my MacBook Pro, and it found no issues.

parser/pageparser/pageparser_test.go

index de7d2e140531ea7808805a0ec4a4c46b35c4cde4..561ad7ea29f389753eb61f805f21d0dd5b92733a 100644 (file)
@@ -22,6 +22,33 @@ import (
        "github.com/gohugoio/hugo/parser/metadecoders"
 )
 
+func FuzzParse(f *testing.F) {
+       samples := []string{
+               `{{< foo >}}`,
+               `{{% foo %}}`,
+               `{{< foo >}} {{< bar >}}`,
+               `---
+title: "Front Matters"
+---
+
+This is some summary. This is some summary. This is some summary. This is some summary.
+
+ <!--more-->
+
+ Foo bars.
+                
+               `,
+       }
+       for _, s := range samples {
+               f.Add([]byte(s))
+       }
+
+       f.Fuzz(func(t *testing.T, b []byte) {
+               cfg := Config{}
+               _, _ = parseBytes(b, cfg, lexIntroSection)
+       })
+}
+
 func BenchmarkParse(b *testing.B) {
        start := `