Prevent panic when incorrect range is provided as PivotTableRange to (#874)

This commit is contained in:
Deepak S 2021-07-10 09:47:41 +05:30 committed by GitHub
parent 2ced00d6a8
commit ee8098037d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

View File

@ -198,6 +198,10 @@ func (f *File) adjustAutoFilterHelper(dir adjustDirection, coordinates []int, nu
// pair of coordinates. // pair of coordinates.
func (f *File) areaRefToCoordinates(ref string) ([]int, error) { func (f *File) areaRefToCoordinates(ref string) ([]int, error) {
rng := strings.Split(strings.Replace(ref, "$", "", -1), ":") rng := strings.Split(strings.Replace(ref, "$", "", -1), ":")
if len(rng) < 2 {
return nil, ErrParameterInvalid
}
return areaRangeToCoordinates(rng[0], rng[1]) return areaRangeToCoordinates(rng[0], rng[1])
} }

View File

@ -228,6 +228,9 @@ func TestAddPivotTable(t *testing.T) {
// Test adjust range with invalid range // Test adjust range with invalid range
_, _, err := f.adjustRange("") _, _, err := f.adjustRange("")
assert.EqualError(t, err, "parameter is required") 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 // Test get pivot fields order with empty data range
_, err = f.getPivotFieldsOrder(&PivotTableOption{}) _, err = f.getPivotFieldsOrder(&PivotTableOption{})
assert.EqualError(t, err, `parameter 'DataRange' parsing error: parameter is required`) assert.EqualError(t, err, `parameter 'DataRange' parsing error: parameter is required`)