diff options
author | Alex Geer <monoflash@gmail.com> | 2019-12-19 19:30:48 +0300 |
---|---|---|
committer | xuri <xuri.me@gmail.com> | 2019-12-20 00:30:48 +0800 |
commit | b1b3c0d15158abc71267da5893de020f047c3872 (patch) | |
tree | 53f9e5a1f42130825572a3c3eea39b2eb4d00f62 /comment.go | |
parent | a00ba75f0f294ce04bfe8d25703d13cd27d6284f (diff) |
Fix #539 Fixed error opening excel file created in encoding d… (#540)
* Fixed issue #539 Fixed error opening excel file created in encoding different from UTF-8, added logging of possible errors when decoding XML if the function does not provide exit with an error
* Added test for CharsetReader
* Fixed #discussion_r359397878
Discussion: https://github.com/360EntSecGroup-Skylar/excelize/pull/540#discussion_r359397878
* Fixed go fmt
* go mod tidy and removed unused imports
* The code has been refactored
Diffstat (limited to 'comment.go')
-rw-r--r-- | comment.go | 23 |
1 files changed, 17 insertions, 6 deletions
@@ -10,9 +10,12 @@ package excelize import ( + "bytes" "encoding/json" "encoding/xml" "fmt" + "io" + "log" "strconv" "strings" ) @@ -303,12 +306,16 @@ func (f *File) countComments() int { // decodeVMLDrawingReader provides a function to get the pointer to the // structure after deserialization of xl/drawings/vmlDrawing%d.xml. func (f *File) decodeVMLDrawingReader(path string) *decodeVmlDrawing { + var err error + if f.DecodeVMLDrawing[path] == nil { c, ok := f.XLSX[path] if ok { - d := decodeVmlDrawing{} - _ = xml.Unmarshal(namespaceStrictToTransitional(c), &d) - f.DecodeVMLDrawing[path] = &d + f.DecodeVMLDrawing[path] = new(decodeVmlDrawing) + if err = f.xmlNewDecoder(bytes.NewReader(namespaceStrictToTransitional(c))). + Decode(f.DecodeVMLDrawing[path]); err != nil && err != io.EOF { + log.Printf("xml decode error: %s", err) + } } } return f.DecodeVMLDrawing[path] @@ -328,12 +335,16 @@ func (f *File) vmlDrawingWriter() { // commentsReader provides a function to get the pointer to the structure // after deserialization of xl/comments%d.xml. func (f *File) commentsReader(path string) *xlsxComments { + var err error + if f.Comments[path] == nil { content, ok := f.XLSX[path] if ok { - c := xlsxComments{} - _ = xml.Unmarshal(namespaceStrictToTransitional(content), &c) - f.Comments[path] = &c + f.Comments[path] = new(xlsxComments) + if err = f.xmlNewDecoder(bytes.NewReader(namespaceStrictToTransitional(content))). + Decode(f.Comments[path]); err != nil && err != io.EOF { + log.Printf("xml decode error: %s", err) + } } } return f.Comments[path] |