Use the call to Coordinate::coordinateFromString() to validate the coordinate passed to createNewCell() _before_ we try adding it to the Collection

This commit is contained in:
MarkBaker 2022-04-30 20:14:36 +02:00
parent e3a6bc1e4c
commit 32559b44a3
2 changed files with 3 additions and 3 deletions

View File

@ -1336,12 +1336,12 @@ class Worksheet implements IComparable
*/ */
public function createNewCell($coordinate) public function createNewCell($coordinate)
{ {
[$column, $row] = Coordinate::coordinateFromString($coordinate);
$cell = new Cell(null, DataType::TYPE_NULL, $this); $cell = new Cell(null, DataType::TYPE_NULL, $this);
$this->cellCollection->add($coordinate, $cell); $this->cellCollection->add($coordinate, $cell);
$this->cellCollectionIsSorted = false; $this->cellCollectionIsSorted = false;
// Coordinates // Coordinates
[$column, $row] = Coordinate::coordinateFromString($coordinate);
$aIndexes = Coordinate::indexesFromString($coordinate); $aIndexes = Coordinate::indexesFromString($coordinate);
if ($this->cachedHighestColumn < $aIndexes[0]) { if ($this->cachedHighestColumn < $aIndexes[0]) {
$this->cachedHighestColumn = $aIndexes[0]; $this->cachedHighestColumn = $aIndexes[0];

View File

@ -72,7 +72,7 @@ class WorksheetNamedRangesTest extends TestCase
$namedCell = 'GOODBYE'; $namedCell = 'GOODBYE';
$this->expectException(Exception::class); $this->expectException(Exception::class);
// $this->expectExceptionMessage("Invalid cell coordinate {$namedCell}"); $this->expectExceptionMessage("Invalid cell coordinate {$namedCell}");
$worksheet = $this->spreadsheet->getActiveSheet(); $worksheet = $this->spreadsheet->getActiveSheet();
$worksheet->getCell($namedCell); $worksheet->getCell($namedCell);
@ -84,7 +84,7 @@ class WorksheetNamedRangesTest extends TestCase
$ucNamedCell = strtoupper($namedCell); $ucNamedCell = strtoupper($namedCell);
$this->expectException(Exception::class); $this->expectException(Exception::class);
// $this->expectExceptionMessage("Invalid cell coordinate {$ucNamedCell}"); $this->expectExceptionMessage("Invalid cell coordinate {$ucNamedCell}");
$worksheet = $this->spreadsheet->getActiveSheet(); $worksheet = $this->spreadsheet->getActiveSheet();
$worksheet->getCell($namedCell); $worksheet->getCell($namedCell);