From bebb8020699ee65bf39fa44380142f3a3d39bc5b Mon Sep 17 00:00:00 2001 From: liuwangchao <59493205+liuwangchao@users.noreply.github.com> Date: Fri, 27 Sep 2024 14:58:18 +0800 Subject: [PATCH] This closes #1999, fix error on GetCellRichText function when read cell without SST index (#2000) - Add unit test for get cell rich text when string item index is invalid - Add comments for the variable ErrPasswordLengthInvalid - Update dependencies modules - Update GitHub Actions workflow configuration, test on Go 1.23.x --- .github/workflows/go.yml | 2 +- cell.go | 4 ++-- cell_test.go | 7 +++++++ errors.go | 3 ++- go.mod | 8 ++++---- go.sum | 16 ++++++++-------- 6 files changed, 24 insertions(+), 16 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 3f100be..6e3db35 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -5,7 +5,7 @@ jobs: test: strategy: matrix: - go-version: [1.18.x, 1.19.x, 1.20.x, '>=1.21.1', 1.22.x] + go-version: [1.18.x, 1.19.x, 1.20.x, '>=1.21.1', 1.22.x, 1.23.x] os: [ubuntu-latest, macos-13, windows-latest] targetplatform: [x86, x64] diff --git a/cell.go b/cell.go index 95caea3..302ea91 100644 --- a/cell.go +++ b/cell.go @@ -1115,11 +1115,11 @@ func (f *File) GetCellRichText(sheet, cell string) (runs []RichTextRun, err erro runs = getCellRichText(c.IS) return } - if c.T == "" { + if c.T != "s" || c.V == "" { return } siIdx, err := strconv.Atoi(c.V) - if err != nil || c.T != "s" { + if err != nil { return } sst, err := f.sharedStringsReader() diff --git a/cell_test.go b/cell_test.go index e64e464..fa67173 100644 --- a/cell_test.go +++ b/cell_test.go @@ -785,6 +785,13 @@ func TestGetCellRichText(t *testing.T) { runs, err = f.GetCellRichText("Sheet1", "A1") assert.NoError(t, err) assert.Equal(t, 0, len(runs)) + // Test get cell rich text when string item index is invalid + ws, ok = f.Sheet.Load("xl/worksheets/sheet1.xml") + assert.True(t, ok) + ws.(*xlsxWorksheet).SheetData.Row[0].C[0] = xlsxC{T: "s", V: "A", IS: &xlsxSI{}} + runs, err = f.GetCellRichText("Sheet1", "A1") + assert.EqualError(t, err, "strconv.Atoi: parsing \"A\": invalid syntax") + assert.Equal(t, 0, len(runs)) // Test get cell rich text on invalid string item index ws, ok = f.Sheet.Load("xl/worksheets/sheet1.xml") assert.True(t, ok) diff --git a/errors.go b/errors.go index dc58b42..55a3c3c 100644 --- a/errors.go +++ b/errors.go @@ -97,7 +97,8 @@ var ( // ErrPasswordLengthInvalid defined the error message on invalid password // length. ErrPasswordLengthInvalid = errors.New("password length invalid") - // ErrPivotTableClassicLayout + // ErrPivotTableClassicLayout defined the error message on enable + // ClassicLayout and CompactData in the same time. ErrPivotTableClassicLayout = errors.New("cannot enable ClassicLayout and CompactData in the same time") // ErrSave defined the error message for saving file. ErrSave = errors.New("no path defined for file, consider File.WriteTo or File.Write") diff --git a/go.mod b/go.mod index c9192e5..7edba1b 100644 --- a/go.mod +++ b/go.mod @@ -8,15 +8,15 @@ require ( github.com/stretchr/testify v1.8.4 github.com/xuri/efp v0.0.0-20240408161823-9ad904a10d6d github.com/xuri/nfp v0.0.0-20240318013403-ab9948c2c4a7 - golang.org/x/crypto v0.26.0 + golang.org/x/crypto v0.27.0 golang.org/x/image v0.18.0 - golang.org/x/net v0.28.0 - golang.org/x/text v0.17.0 + golang.org/x/net v0.29.0 + golang.org/x/text v0.18.0 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/richardlehane/msoleps v1.0.3 // indirect + github.com/richardlehane/msoleps v1.0.4 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 346cd77..de22a1d 100644 --- a/go.sum +++ b/go.sum @@ -7,22 +7,22 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/richardlehane/mscfb v1.0.4 h1:WULscsljNPConisD5hR0+OyZjwK46Pfyr6mPu5ZawpM= github.com/richardlehane/mscfb v1.0.4/go.mod h1:YzVpcZg9czvAuhk9T+a3avCpcFPMUWm7gK3DypaEsUk= github.com/richardlehane/msoleps v1.0.1/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg= -github.com/richardlehane/msoleps v1.0.3 h1:aznSZzrwYRl3rLKRT3gUk9am7T/mLNSnJINvN0AQoVM= -github.com/richardlehane/msoleps v1.0.3/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg= +github.com/richardlehane/msoleps v1.0.4 h1:WuESlvhX3gH2IHcd8UqyCuFY5yiq/GR/yqaSM/9/g00= +github.com/richardlehane/msoleps v1.0.4/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/xuri/efp v0.0.0-20240408161823-9ad904a10d6d h1:llb0neMWDQe87IzJLS4Ci7psK/lVsjIS2otl+1WyRyY= github.com/xuri/efp v0.0.0-20240408161823-9ad904a10d6d/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI= github.com/xuri/nfp v0.0.0-20240318013403-ab9948c2c4a7 h1:hPVCafDV85blFTabnqKgNhDCkJX25eik94Si9cTER4A= github.com/xuri/nfp v0.0.0-20240318013403-ab9948c2c4a7/go.mod h1:WwHg+CVyzlv/TX9xqBFXEZAuxOPxn2k1GNHwG41IIUQ= -golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= -golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= +golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A= +golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70= golang.org/x/image v0.18.0 h1:jGzIakQa/ZXI1I0Fxvaa9W7yP25TqT6cHIHn+6CqvSQ= golang.org/x/image v0.18.0/go.mod h1:4yyo5vMFQjVjUcVk4jEQcU9MGy/rulF5WvUILseCM2E= -golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE= -golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg= -golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= -golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo= +golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0= +golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224= +golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=