diff options
author | Martin Martinez Rivera <mrtnz.rvr@gmail.com> | 2022-11-04 21:41:07 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-05 12:41:07 +0800 |
commit | 75c912ca952bf47bbe421030554ef580ff4f3996 (patch) | |
tree | 227d6e6db5c33fb3e298ac3fa75f9a1df96ede9c /cell_test.go | |
parent | 4998b7b92980e1139b3f38d3c2b8cbc11b1a629d (diff) |
This closes #1384, fix segmentation fault in `formattedValue` (#1385)
- Add nil pointer guard in cell format
- Add tests to verify the nil checks in formattedValue
Co-authored-by: Zach Clark <zachmclark@gmail.com>
Diffstat (limited to 'cell_test.go')
-rw-r--r-- | cell_test.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/cell_test.go b/cell_test.go index f741211..6689c36 100644 --- a/cell_test.go +++ b/cell_test.go @@ -744,6 +744,35 @@ func TestFormattedValue2(t *testing.T) { } } +func TestFormattedValueNilXfs(t *testing.T) { + // Set the CellXfs to nil and verify that the formattedValue function does not crash. + f := NewFile() + f.Styles.CellXfs = nil + assert.Equal(t, "43528", f.formattedValue(3, "43528", false)) +} + +func TestFormattedValueNilNumFmts(t *testing.T) { + // Set the NumFmts value to nil and verify that the formattedValue function does not crash. + f := NewFile() + f.Styles.NumFmts = nil + assert.Equal(t, "43528", f.formattedValue(3, "43528", false)) +} + +func TestFormattedValueNilWorkbook(t *testing.T) { + // Set the Workbook value to nil and verify that the formattedValue function does not crash. + f := NewFile() + f.WorkBook = nil + assert.Equal(t, "43528", f.formattedValue(3, "43528", false)) +} + +func TestFormattedValueNilWorkbookPr(t *testing.T) { + // Set the WorkBook.WorkbookPr value to nil and verify that the formattedValue function does not + // crash. + f := NewFile() + f.WorkBook.WorkbookPr = nil + assert.Equal(t, "43528", f.formattedValue(3, "43528", false)) +} + func TestSharedStringsError(t *testing.T) { f, err := OpenFile(filepath.Join("test", "Book1.xlsx"), Options{UnzipXMLSizeLimit: 128}) assert.NoError(t, err) |