Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid Html Due to Cached Filesize #4184

Merged
merged 3 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.\*)

Expand Down
1 change: 1 addition & 0 deletions src/PhpSpreadsheet/Reader/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '';
Expand Down
46 changes: 46 additions & 0 deletions tests/PhpSpreadsheetTests/Reader/Html/Issue1107Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

namespace PhpOffice\PhpSpreadsheetTests\Reader\Html;

use PhpOffice\PhpSpreadsheet\Reader\Html as HtmlReader;
use PhpOffice\PhpSpreadsheet\Shared\File;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Html as HtmlWriter;
use PHPUnit\Framework\TestCase;

class Issue1107Test extends TestCase
{
private string $outfile = '';

protected function tearDown(): void
{
if ($this->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();
}
}
Loading