Skip to content

Commit

Permalink
fix: fix nil sheet model append nil pointer reference.
Browse files Browse the repository at this point in the history
  • Loading branch information
VarusHsu committed May 27, 2024
1 parent 3d92f7b commit 840c605
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ func write(sheetModels []SheetModel, opts ...Option) (*excelize.File, error) {
f := excelize.NewFile()
sheetLinesCount := make(map[string]int)
for _, sheetModel := range sheetModels {
if sheetModel == nil {
return nil, errors.New("nil reference row append is not allowed")
}
sheetName := sheetModel.SheetName()
if sheetName == "" {
return nil, errors.New("sheetModel must have a sheet name")
Expand Down
8 changes: 8 additions & 0 deletions build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,3 +379,11 @@ func TestWithHeadless(t *testing.T) {
t.Error(err)
}
}

func TestAppendNilRow(t *testing.T) {
var models []SheetModel
models = append(models, nil)
err := WriteExcelSaveAs("test16.xlsx", models)
assert.EqualError(t, err, "nil reference row append is not allowed")

}

0 comments on commit 840c605

Please sign in to comment.