From 6b59c00eb2803eda22261a3347b080244874945f Mon Sep 17 00:00:00 2001 From: JP Appel Date: Thu, 12 Jun 2025 02:15:59 -0400 Subject: Change doc parsing to only read YAML header Fixes unintended YAML decode errors when a documents has a valid header but the rest of its contents are not valid YAML. --- pkg/index/index.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'pkg/index/index.go') diff --git a/pkg/index/index.go b/pkg/index/index.go index 15a5e86..5d23e14 100644 --- a/pkg/index/index.go +++ b/pkg/index/index.go @@ -329,7 +329,14 @@ func ParseDoc(path string) (*Document, error) { } doc.FileTime = info.ModTime() - if err := yaml.NewDecoder(f).Decode(doc); err != nil { + pos := yamlHeaderPos(f) + f.Seek(0, io.SeekStart) + if pos < 0 { + return nil, fmt.Errorf("Can't find YAML header in %s", path) + } + + // FIXME: decoder reads past yaml header into document + if err := yaml.NewDecoder(io.LimitReader(f, pos)).Decode(doc); err != nil { return nil, errors.Join(ErrHeaderParse, err) } -- cgit v1.2.3