Skip to content

Commit 5878fbd

Browse files
authored
This closes #1503, case-insensitive for the file extension name
1 parent a34c81e commit 5878fbd

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

file.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"io"
1919
"os"
2020
"path/filepath"
21+
"strings"
2122
"sync"
2223
)
2324

@@ -73,7 +74,7 @@ func (f *File) SaveAs(name string, opts ...Options) error {
7374
return ErrMaxFilePathLength
7475
}
7576
f.Path = name
76-
if _, ok := supportedContentTypes[filepath.Ext(f.Path)]; !ok {
77+
if _, ok := supportedContentTypes[strings.ToLower(filepath.Ext(f.Path))]; !ok {
7778
return ErrWorkbookFileFormat
7879
}
7980
file, err := os.OpenFile(filepath.Clean(name), os.O_WRONLY|os.O_TRUNC|os.O_CREATE, os.ModePerm)
@@ -116,7 +117,7 @@ func (f *File) WriteTo(w io.Writer, opts ...Options) (int64, error) {
116117
f.options = &opts[i]
117118
}
118119
if len(f.Path) != 0 {
119-
contentType, ok := supportedContentTypes[filepath.Ext(f.Path)]
120+
contentType, ok := supportedContentTypes[strings.ToLower(filepath.Ext(f.Path))]
120121
if !ok {
121122
return 0, ErrWorkbookFileFormat
122123
}

picture.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func (f *File) AddPicture(sheet, cell, name string, opts *GraphicOptions) error
151151
if _, err = os.Stat(name); os.IsNotExist(err) {
152152
return err
153153
}
154-
ext, ok := supportedImageTypes[path.Ext(name)]
154+
ext, ok := supportedImageTypes[strings.ToLower(path.Ext(name))]
155155
if !ok {
156156
return ErrImgExt
157157
}
@@ -202,7 +202,7 @@ func (f *File) AddPicture(sheet, cell, name string, opts *GraphicOptions) error
202202
func (f *File) AddPictureFromBytes(sheet, cell string, pic *Picture) error {
203203
var drawingHyperlinkRID int
204204
var hyperlinkType string
205-
ext, ok := supportedImageTypes[pic.Extension]
205+
ext, ok := supportedImageTypes[strings.ToLower(pic.Extension)]
206206
if !ok {
207207
return ErrImgExt
208208
}
@@ -659,7 +659,7 @@ func (f *File) getPicture(row, col int, drawingXML, drawingRelationships string)
659659
if err = nil; deTwoCellAnchor.From != nil && deTwoCellAnchor.Pic != nil {
660660
if deTwoCellAnchor.From.Col == col && deTwoCellAnchor.From.Row == row {
661661
drawRel = f.getDrawingRelationships(drawingRelationships, deTwoCellAnchor.Pic.BlipFill.Blip.Embed)
662-
if _, ok = supportedImageTypes[filepath.Ext(drawRel.Target)]; ok {
662+
if _, ok = supportedImageTypes[strings.ToLower(filepath.Ext(drawRel.Target))]; ok {
663663
pic := Picture{Extension: filepath.Ext(drawRel.Target), Format: &GraphicOptions{}}
664664
if buffer, _ := f.Pkg.Load(strings.ReplaceAll(drawRel.Target, "..", "xl")); buffer != nil {
665665
pic.File = buffer.([]byte)
@@ -690,7 +690,7 @@ func (f *File) getPicturesFromWsDr(row, col int, drawingRelationships string, ws
690690
if anchor.From.Col == col && anchor.From.Row == row {
691691
if drawRel = f.getDrawingRelationships(drawingRelationships,
692692
anchor.Pic.BlipFill.Blip.Embed); drawRel != nil {
693-
if _, ok = supportedImageTypes[filepath.Ext(drawRel.Target)]; ok {
693+
if _, ok = supportedImageTypes[strings.ToLower(filepath.Ext(drawRel.Target))]; ok {
694694
pic := Picture{Extension: filepath.Ext(drawRel.Target), Format: &GraphicOptions{}}
695695
if buffer, _ := f.Pkg.Load(strings.ReplaceAll(drawRel.Target, "..", "xl")); buffer != nil {
696696
pic.File = buffer.([]byte)

sheet.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ func (f *File) SetSheetBackgroundFromBytes(sheet, extension string, picture []by
525525
// setSheetBackground provides a function to set background picture by given
526526
// worksheet name, file name extension and image data.
527527
func (f *File) setSheetBackground(sheet, extension string, file []byte) error {
528-
imageType, ok := supportedImageTypes[extension]
528+
imageType, ok := supportedImageTypes[strings.ToLower(extension)]
529529
if !ok {
530530
return ErrImgExt
531531
}

0 commit comments

Comments
 (0)