Skip to content

Commit

Permalink
This closes qax-os#1432, fix panic formattedValue when style is negat…
Browse files Browse the repository at this point in the history
…ive (qax-os#1433)
  • Loading branch information
liron-l authored Dec 28, 2022
1 parent 0c76766 commit a57203a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cell.go
Original file line number Diff line number Diff line change
Expand Up @@ -1319,7 +1319,7 @@ func (f *File) formattedValue(s int, v string, raw bool) (string, error) {
if styleSheet.CellXfs == nil {
return v, err
}
if s >= len(styleSheet.CellXfs.Xf) {
if s >= len(styleSheet.CellXfs.Xf) || s < 0 {
return v, err
}
var numFmtID int
Expand Down
9 changes: 7 additions & 2 deletions cell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package excelize

import (
"fmt"
_ "image/jpeg"
"os"
"path/filepath"
"reflect"
Expand All @@ -11,8 +12,6 @@ import (
"testing"
"time"

_ "image/jpeg"

"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -755,10 +754,16 @@ func TestFormattedValue(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, "43528", result)

// S is too large
result, err = f.formattedValue(15, "43528", false)
assert.NoError(t, err)
assert.Equal(t, "43528", result)

// S is too small
result, err = f.formattedValue(-15, "43528", false)
assert.NoError(t, err)
assert.Equal(t, "43528", result)

result, err = f.formattedValue(1, "43528", false)
assert.NoError(t, err)
assert.Equal(t, "43528", result)
Expand Down

0 comments on commit a57203a

Please sign in to comment.