Skip to content

Commit a64efca

Browse files
committed
This fixes qax-os#1888, read internal media files with absolute path
1 parent 781c384 commit a64efca

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

picture.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -598,15 +598,15 @@ func (f *File) getPicture(row, col int, drawingXML, drawingRelationships string)
598598
cond2 := func(from *decodeFrom) bool { return from.Col == col && from.Row == row }
599599
cb := func(a *xdrCellAnchor, r *xlsxRelationship) {
600600
pic := Picture{Extension: filepath.Ext(r.Target), Format: &GraphicOptions{}, InsertType: PictureInsertTypePlaceOverCells}
601-
if buffer, _ := f.Pkg.Load(strings.ReplaceAll(r.Target, "..", "xl")); buffer != nil {
601+
if buffer, _ := f.Pkg.Load(filepath.ToSlash(filepath.Clean("xl/drawings/" + r.Target))); buffer != nil {
602602
pic.File = buffer.([]byte)
603603
pic.Format.AltText = a.Pic.NvPicPr.CNvPr.Descr
604604
pics = append(pics, pic)
605605
}
606606
}
607607
cb2 := func(a *decodeCellAnchor, r *xlsxRelationship) {
608608
pic := Picture{Extension: filepath.Ext(r.Target), Format: &GraphicOptions{}, InsertType: PictureInsertTypePlaceOverCells}
609-
if buffer, _ := f.Pkg.Load(strings.ReplaceAll(r.Target, "..", "xl")); buffer != nil {
609+
if buffer, _ := f.Pkg.Load(filepath.ToSlash(filepath.Clean("xl/drawings/" + r.Target))); buffer != nil {
610610
pic.File = buffer.([]byte)
611611
pic.Format.AltText = a.Pic.NvPicPr.CNvPr.Descr
612612
pics = append(pics, pic)
@@ -756,14 +756,14 @@ func (f *File) getPictureCells(drawingXML, drawingRelationships string) ([]strin
756756
cond := func(from *xlsxFrom) bool { return true }
757757
cond2 := func(from *decodeFrom) bool { return true }
758758
cb := func(a *xdrCellAnchor, r *xlsxRelationship) {
759-
if _, ok := f.Pkg.Load(strings.ReplaceAll(r.Target, "..", "xl")); ok {
759+
if _, ok := f.Pkg.Load(filepath.ToSlash(filepath.Clean("xl/drawings/" + r.Target))); ok {
760760
if cell, err := CoordinatesToCellName(a.From.Col+1, a.From.Row+1); err == nil && inStrSlice(cells, cell, true) == -1 {
761761
cells = append(cells, cell)
762762
}
763763
}
764764
}
765765
cb2 := func(a *decodeCellAnchor, r *xlsxRelationship) {
766-
if _, ok := f.Pkg.Load(strings.ReplaceAll(r.Target, "..", "xl")); ok {
766+
if _, ok := f.Pkg.Load(filepath.ToSlash(filepath.Clean("xl/drawings/" + r.Target))); ok {
767767
if cell, err := CoordinatesToCellName(a.From.Col+1, a.From.Row+1); err == nil && inStrSlice(cells, cell, true) == -1 {
768768
cells = append(cells, cell)
769769
}

0 commit comments

Comments
 (0)