-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Html Reader Converting Cell Containing 0 to Null String (#2813)
Fix #2810. Repairing some Phpstan diagnostics, used `?:` rather than `??` in a few places. 2 different Html modules are affected. Also, Ods Reader, but its problem is with sheet title rather than cell contents. And, as it turns out, Ods Reader was already not handling sheets with a title of `0` correctly - it made a truthy test before setting sheet title. That is now changed to truthy or numeric. Other readers are not susceptible to this problem. Tests are added.
- Loading branch information
Showing
8 changed files
with
66 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace PhpOffice\PhpSpreadsheetTests\Reader\Html; | ||
|
||
use PhpOffice\PhpSpreadsheet\Reader\Html; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class Issue2810Test extends TestCase | ||
{ | ||
// Reader has been converting falsey values to null | ||
public function testIssue2810(): void | ||
{ | ||
$content = <<<'EOF' | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset='utf-8'> | ||
<title>Declaracion en Linea</title> | ||
</head> | ||
<body> | ||
<table> | ||
<tr> | ||
<td>1</td> | ||
<td>0</td> | ||
<td>2</td> | ||
</tr> | ||
</table> | ||
</body> | ||
</html> | ||
|
||
EOF; | ||
$reader = new Html(); | ||
$spreadsheet = $reader->loadFromString($content); | ||
$sheet = $spreadsheet->getActiveSheet(); | ||
self::assertSame(1, $sheet->getCell('A1')->getValue()); | ||
self::assertSame(0, $sheet->getCell('B1')->getValue()); | ||
self::assertSame(2, $sheet->getCell('C1')->getValue()); | ||
$spreadsheet->disconnectWorksheets(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace PhpOffice\PhpSpreadsheetTests\Reader\Ods; | ||
|
||
use PhpOffice\PhpSpreadsheet\Reader\Ods; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class Issue2810Test extends TestCase | ||
{ | ||
public function testIssue2810(): void | ||
{ | ||
// Active sheet with title of '0' wasn't found | ||
$filename = 'tests/data/Reader/Ods/issue.2810.ods'; | ||
$reader = new Ods(); | ||
$spreadsheet = $reader->load($filename); | ||
$sheet = $spreadsheet->getActiveSheet(); | ||
self::assertSame('Active', $sheet->getCell('A1')->getValue()); | ||
$spreadsheet->disconnectWorksheets(); | ||
} | ||
} |
Binary file not shown.