aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/index/index.go
diff options
context:
space:
mode:
authorJP Appel <jeanpierre.appel01@gmail.com>2025-06-12 02:15:59 -0400
committerJP Appel <jeanpierre.appel01@gmail.com>2025-06-12 02:15:59 -0400
commit6b59c00eb2803eda22261a3347b080244874945f (patch)
tree6dd0ec7241df3732e98b86c89b79a75ee8f20a3e /pkg/index/index.go
parent96e68148369e4076bcee45f91810669e4898c59e (diff)
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.
Diffstat (limited to 'pkg/index/index.go')
-rw-r--r--pkg/index/index.go9
1 files changed, 8 insertions, 1 deletions
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)
}