Skip to content

Commit b69a802

Browse files
liron-lxuri
authored andcommitted
This closes qax-os#1432, fix panic formattedValue when style is negative (qax-os#1433)
1 parent 45c4b72 commit b69a802

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

cell.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1319,7 +1319,7 @@ func (f *File) formattedValue(s int, v string, raw bool) (string, error) {
13191319
if styleSheet.CellXfs == nil {
13201320
return v, err
13211321
}
1322-
if s >= len(styleSheet.CellXfs.Xf) {
1322+
if s >= len(styleSheet.CellXfs.Xf) || s < 0 {
13231323
return v, err
13241324
}
13251325
var numFmtID int

cell_test.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package excelize
22

33
import (
44
"fmt"
5+
_ "image/jpeg"
56
"os"
67
"path/filepath"
78
"reflect"
@@ -11,8 +12,6 @@ import (
1112
"testing"
1213
"time"
1314

14-
_ "image/jpeg"
15-
1615
"github.com/stretchr/testify/assert"
1716
)
1817

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

757+
// S is too large
758758
result, err = f.formattedValue(15, "43528", false)
759759
assert.NoError(t, err)
760760
assert.Equal(t, "43528", result)
761761

762+
// S is too small
763+
result, err = f.formattedValue(-15, "43528", false)
764+
assert.NoError(t, err)
765+
assert.Equal(t, "43528", result)
766+
762767
result, err = f.formattedValue(1, "43528", false)
763768
assert.NoError(t, err)
764769
assert.Equal(t, "43528", result)

0 commit comments

Comments
 (0)