1
0
mirror of https://github.com/pbnjay/grate.git synced 2026-05-16 09:08:09 +02:00

deal with malformed "absolute" paths in relationship Targets

such as #8 and more robust fix than #9
This commit is contained in:
Jeremy Jay
2022-08-09 19:17:34 -04:00
parent e2d22a3b93
commit 6f2eabdf18
+7 -1
View File
@@ -7,6 +7,7 @@ import (
"log"
"path/filepath"
"strconv"
"strings"
"github.com/pbnjay/grate"
)
@@ -27,7 +28,12 @@ func (d *Document) parseRels(dec *xml.Decoder, basedir string) error {
if _, ok := d.rels[vals["Type"]]; !ok {
d.rels[vals["Type"]] = make(map[string]string)
}
d.rels[vals["Type"]][vals["Id"]] = filepath.Join(basedir, vals["Target"])
if strings.HasPrefix(vals["Target"], "/") {
// handle malformed "absolute" paths cleanly
d.rels[vals["Type"]][vals["Id"]] = vals["Target"][1:]
} else {
d.rels[vals["Type"]][vals["Id"]] = filepath.Join(basedir, vals["Target"])
}
if vals["Type"] == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" {
d.primaryDoc = vals["Target"]
}