Skip to content

Commit 99903a3

Browse files
authored
This fixes GHSA-g27h-8qhm-6pff, prevent panic on a worksheet with an empty merged cell reference (#2379)
- Update unit tests
1 parent ee9c6fc commit 99903a3

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

cell.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,6 +1657,9 @@ func (ws *xlsxWorksheet) mergeCellsParser(cell string) (string, error) {
16571657
_ = sortCoordinates(rect)
16581658
ws.MergeCells.Cells[i].rect = rect
16591659
}
1660+
if len(ws.MergeCells.Cells[i].rect) == 0 {
1661+
continue
1662+
}
16601663
if cellInRange([]int{col, row}, ws.MergeCells.Cells[i].rect) {
16611664
cell = strings.Split(ws.MergeCells.Cells[i].Ref, ":")[0]
16621665
break

merge_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,4 +238,10 @@ func TestMergeCellsParser(t *testing.T) {
238238
ws := &xlsxWorksheet{MergeCells: &xlsxMergeCells{Cells: []*xlsxMergeCell{nil}}}
239239
_, err := ws.mergeCellsParser("A1")
240240
assert.NoError(t, err)
241+
242+
// Test parse merged cells with empty merged cell reference
243+
ws = &xlsxWorksheet{MergeCells: &xlsxMergeCells{Cells: []*xlsxMergeCell{{Ref: ""}}}}
244+
cell, err := ws.mergeCellsParser("A1")
245+
assert.NoError(t, err)
246+
assert.Equal(t, "A1", cell)
241247
}

0 commit comments

Comments
 (0)