Fixed #825, improves compatibility for comments with absolute XML path

v2
xuri 4 years ago
parent f5a20fa03f
commit e5c5ecc379
No known key found for this signature in database
GPG Key ID: BA5E5BB1C948EDF7

@ -39,7 +39,14 @@ func parseFormatCommentsSet(formatSet string) (*formatComment, error) {
func (f *File) GetComments() (comments map[string][]Comment) { func (f *File) GetComments() (comments map[string][]Comment) {
comments = map[string][]Comment{} comments = map[string][]Comment{}
for n, path := range f.sheetMap { for n, path := range f.sheetMap {
if d := f.commentsReader("xl" + strings.TrimPrefix(f.getSheetComments(filepath.Base(path)), "..")); d != nil { target := f.getSheetComments(filepath.Base(path))
if target == "" {
continue
}
if !filepath.IsAbs(target) {
target = "xl" + strings.TrimPrefix(target, "..")
}
if d := f.commentsReader(strings.TrimPrefix(target, "/")); d != nil {
sheetComments := []Comment{} sheetComments := []Comment{}
for _, comment := range d.CommentList.Comment { for _, comment := range d.CommentList.Comment {
sheetComment := Comment{} sheetComment := Comment{}

@ -40,6 +40,7 @@ func TestAddComments(t *testing.T) {
comments := f.GetComments() comments := f.GetComments()
assert.EqualValues(t, 2, len(comments["Sheet1"])) assert.EqualValues(t, 2, len(comments["Sheet1"]))
assert.EqualValues(t, 1, len(comments["Sheet2"])) assert.EqualValues(t, 1, len(comments["Sheet2"]))
assert.EqualValues(t, len(NewFile().GetComments()), 0)
} }
func TestDecodeVMLDrawingReader(t *testing.T) { func TestDecodeVMLDrawingReader(t *testing.T) {

Loading…
Cancel
Save