Minimum Table range validation

Range must be at least 1 column and 2 rows
This commit is contained in:
aswinkumar863 2022-04-17 17:45:17 +05:30
parent 3c4a51acb5
commit ea3263650b
No known key found for this signature in database
GPG Key ID: 8A69BFA6AEF8FA3E
2 changed files with 21 additions and 4 deletions

View File

@ -190,6 +190,11 @@ class Table
throw new PhpSpreadsheetException('Table must be set on a range of cells.');
}
[$width, $height] = Coordinate::rangeDimension($range);
if ($width < 1 || $height < 2) {
throw new PhpSpreadsheetException('The table range must be at least 1 column and 2 rows');
}
$this->range = $range;
// Discard any column ruless that are no longer valid within this range
[$rangeStart, $rangeEnd] = Coordinate::rangeBoundaries($this->range);

View File

@ -173,14 +173,26 @@ class TableTest extends SetupTeardown
self::assertEquals($expectedResult, $result);
}
public function testSetRangeInvalidRange(): void
/**
* @dataProvider invalidTableRangeProvider
*/
public function testSetRangeInvalidRange(string $range): void
{
$this->expectException(PhpSpreadsheetException::class);
$expectedResult = 'A1';
$sheet = $this->getSheet();
$table = new Table($expectedResult, $sheet);
new Table($range, $sheet);
}
public function invalidTableRangeProvider(): array
{
return [
['A1'],
['A1:A1'],
['B1:A4'],
['A1:D1'],
['D1:A1'],
];
}
public function testGetColumnsEmpty(): void