From 6f2eabdf189ccd1a53ee3fa2f2df511346934d74 Mon Sep 17 00:00:00 2001 From: Jeremy Jay Date: Tue, 9 Aug 2022 19:17:34 -0400 Subject: [PATCH] deal with malformed "absolute" paths in relationship Targets such as #8 and more robust fix than #9 --- xlsx/workbook.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/xlsx/workbook.go b/xlsx/workbook.go index 4971554..d789562 100644 --- a/xlsx/workbook.go +++ b/xlsx/workbook.go @@ -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"] }