summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDeepak S <in.live.in@live.in>2021-07-10 09:47:41 +0530
committerGitHub <noreply@github.com>2021-07-10 12:17:41 +0800
commitee8098037dc71028e755ae62dfeb823c0e7b366e (patch)
tree0c4732b583e1f1af57ccb3d9e79896c5e64ba621
parent2ced00d6a82f993094858e60127d4f817ad788e3 (diff)
Prevent panic when incorrect range is provided as PivotTableRange to (#874)
-rw-r--r--adjust.go4
-rw-r--r--pivotTable_test.go3
2 files changed, 7 insertions, 0 deletions
diff --git a/adjust.go b/adjust.go
index 28b62cc..ef7b19a 100644
--- a/adjust.go
+++ b/adjust.go
@@ -198,6 +198,10 @@ func (f *File) adjustAutoFilterHelper(dir adjustDirection, coordinates []int, nu
// pair of coordinates.
func (f *File) areaRefToCoordinates(ref string) ([]int, error) {
rng := strings.Split(strings.Replace(ref, "$", "", -1), ":")
+ if len(rng) < 2 {
+ return nil, ErrParameterInvalid
+ }
+
return areaRangeToCoordinates(rng[0], rng[1])
}
diff --git a/pivotTable_test.go b/pivotTable_test.go
index e746d8d..bf6bb01 100644
--- a/pivotTable_test.go
+++ b/pivotTable_test.go
@@ -228,6 +228,9 @@ func TestAddPivotTable(t *testing.T) {
// Test adjust range with invalid range
_, _, err := f.adjustRange("")
assert.EqualError(t, err, "parameter is required")
+ // Test adjust range with incorrect range
+ _, _, err = f.adjustRange("sheet1!")
+ assert.EqualError(t, err, "parameter is invalid")
// Test get pivot fields order with empty data range
_, err = f.getPivotFieldsOrder(&PivotTableOption{})
assert.EqualError(t, err, `parameter 'DataRange' parsing error: parameter is required`)