Skip to content

Commit 3194757

Browse files
authored
Merge pull request #4184 from oleibman/issue1107
Invalid Html Due to Cached Filesize
2 parents 88c517f + 5fcce81 commit 3194757

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
3131
- SUMIFS Does Not Require xlfn. [Issue #4182](https://github.com/PHPOffice/PhpSpreadsheet/issues/4182) [PR #4186](https://github.com/PHPOffice/PhpSpreadsheet/pull/4186)
3232
- 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)
3333
- 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)
34+
- Invalid Html Due to Cached Filesize. [Issue #1107](https://github.com/PHPOffice/PhpSpreadsheet/issues/1107) [PR #4184](https://github.com/PHPOffice/PhpSpreadsheet/pull/4184)
3435

3536
## 2024-09-29 - 3.3.0 (no 3.0.\*, 3.1.\*, 3.2.\*)
3637

src/PhpSpreadsheet/Reader/Html.php

+1
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ private function readEnding(): string
173173
// Phpstan incorrectly flags following line for Php8.2-, corrected in 8.3
174174
$filename = $meta['uri']; //@phpstan-ignore-line
175175

176+
clearstatcache(true, $filename);
176177
$size = (int) filesize($filename);
177178
if ($size === 0) {
178179
return '';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpOffice\PhpSpreadsheetTests\Reader\Html;
6+
7+
use PhpOffice\PhpSpreadsheet\Reader\Html as HtmlReader;
8+
use PhpOffice\PhpSpreadsheet\Shared\File;
9+
use PhpOffice\PhpSpreadsheet\Spreadsheet;
10+
use PhpOffice\PhpSpreadsheet\Writer\Html as HtmlWriter;
11+
use PHPUnit\Framework\TestCase;
12+
13+
class Issue1107Test extends TestCase
14+
{
15+
private string $outfile = '';
16+
17+
protected function tearDown(): void
18+
{
19+
if ($this->outfile !== '') {
20+
unlink($this->outfile);
21+
$this->outfile = '';
22+
}
23+
}
24+
25+
public function testIssue1107(): void
26+
{
27+
// failure due to cached file size
28+
$outstr = str_repeat('a', 1023) . "\n";
29+
$allout = str_repeat($outstr, 10);
30+
$this->outfile = $outfile = File::temporaryFilename();
31+
file_put_contents($outfile, $allout);
32+
self::assertSame(10240, filesize($outfile));
33+
$spreadsheet = new Spreadsheet();
34+
$sheet = $spreadsheet->getActiveSheet();
35+
$sheet->getCell('A1')->setValue(1);
36+
$writer = new HtmlWriter($spreadsheet);
37+
$writer->save($outfile);
38+
$spreadsheet->disconnectWorksheets();
39+
$reader = new HtmlReader();
40+
$spreadsheet2 = $reader->load($outfile);
41+
$sheet2 = $spreadsheet2->getActiveSheet();
42+
self::assertSame(1, $sheet2->getCell('A1')->getValue());
43+
44+
$spreadsheet2->disconnectWorksheets();
45+
}
46+
}

0 commit comments

Comments
 (0)