From 6382dba985651ab6d266fd2a23b598d4c9b0e1da Mon Sep 17 00:00:00 2001 From: oleibman <10341515+oleibman@users.noreply.github.com> Date: Sat, 5 Oct 2024 23:15:57 -0700 Subject: [PATCH 1/2] Invalid Html Due to Cached Filesize Fix #1107. Clear statcache for file before requesting its size. --- src/PhpSpreadsheet/Reader/Html.php | 1 + .../Reader/Html/Issue1107Test.php | 46 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 tests/PhpSpreadsheetTests/Reader/Html/Issue1107Test.php diff --git a/src/PhpSpreadsheet/Reader/Html.php b/src/PhpSpreadsheet/Reader/Html.php index 2a2ffc410c..15b6c7677f 100644 --- a/src/PhpSpreadsheet/Reader/Html.php +++ b/src/PhpSpreadsheet/Reader/Html.php @@ -173,6 +173,7 @@ private function readEnding(): string // Phpstan incorrectly flags following line for Php8.2-, corrected in 8.3 $filename = $meta['uri']; //@phpstan-ignore-line + clearstatcache(true, $filename); $size = (int) filesize($filename); if ($size === 0) { return ''; diff --git a/tests/PhpSpreadsheetTests/Reader/Html/Issue1107Test.php b/tests/PhpSpreadsheetTests/Reader/Html/Issue1107Test.php new file mode 100644 index 0000000000..8668500839 --- /dev/null +++ b/tests/PhpSpreadsheetTests/Reader/Html/Issue1107Test.php @@ -0,0 +1,46 @@ +outfile !== '') { + unlink($this->outfile); + $this->outfile = ''; + } + } + + public function testIssue1107(): void + { + // failure due to cached file size + $outstr = str_repeat('a', 1023) . "\n"; + $allout = str_repeat($outstr, 10); + $this->outfile = $outfile = File::temporaryFilename(); + file_put_contents($outfile, $allout); + self::assertSame(10240, filesize($outfile)); + $spreadsheet = new Spreadsheet(); + $sheet = $spreadsheet->getActiveSheet(); + $sheet->getCell('A1')->setValue(1); + $writer = new HtmlWriter($spreadsheet); + $writer->save($outfile); + $spreadsheet->disconnectWorksheets(); + $reader = new HtmlReader(); + $spreadsheet2 = $reader->load($outfile); + $sheet2 = $spreadsheet2->getActiveSheet(); + self::assertSame(1, $sheet2->getCell('A1')->getValue()); + + $spreadsheet2->disconnectWorksheets(); + } +} From 5fcce81eed279356f43fdfea09c8448f355e6749 Mon Sep 17 00:00:00 2001 From: oleibman <10341515+oleibman@users.noreply.github.com> Date: Wed, 9 Oct 2024 06:08:09 -0700 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 69d4c9ef03..21033ec6ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - SUMIFS Does Not Require xlfn. [Issue #4182](https://github.com/PHPOffice/PhpSpreadsheet/issues/4182) [PR #4186](https://github.com/PHPOffice/PhpSpreadsheet/pull/4186) - Image Transparency/Opacity with Html Reader Changes. [Discussion #4117](https://github.com/PHPOffice/PhpSpreadsheet/discussions/4117) [PR #4142](https://github.com/PHPOffice/PhpSpreadsheet/pull/4142) - Option to Write Hyperlink Rather Than Label to Csv. [Issue #1412](https://github.com/PHPOffice/PhpSpreadsheet/issues/1412) [PR #4151](https://github.com/PHPOffice/PhpSpreadsheet/pull/4151) +- Invalid Html Due to Cached Filesize. [Issue #1107](https://github.com/PHPOffice/PhpSpreadsheet/issues/1107) [PR #4184](https://github.com/PHPOffice/PhpSpreadsheet/pull/4184) ## 2024-09-29 - 3.3.0 (no 3.0.\*, 3.1.\*, 3.2.\*)