Skip to content

Commit fbd4070

Browse files
authored
Merge pull request #4524 from oleibman/issue4521
Recognize "New" Mimetype for Empty File
2 parents b271cbf + 3eff3b4 commit fbd4070

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
2929

3030
### Fixed
3131

32+
- Recognize application/x-empty mimetype. [Issue #4521](https://github.com/PHPOffice/PhpSpreadsheet/issues/4521) [PR #4524](https://github.com/PHPOffice/PhpSpreadsheet/pull/4524)
3233
- Micro-optimization in getSheetByName. [PR #4499](https://github.com/PHPOffice/PhpSpreadsheet/pull/4499)
3334
- Bug in resizeMatricesExtend. [Issue #4451](https://github.com/PHPOffice/PhpSpreadsheet/issues/4451) [PR #4474](https://github.com/PHPOffice/PhpSpreadsheet/pull/4474)
3435

src/PhpSpreadsheet/Reader/Csv.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,7 @@ public function canRead(string $filename): bool
605605
'text/csv',
606606
'text/plain',
607607
'inode/x-empty',
608+
'application/x-empty', // has now replaced previous
608609
'text/html',
609610
];
610611

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
namespace PhpOffice\PhpSpreadsheetTests;
4+
5+
use PhpOffice\PhpSpreadsheet\IOFactory;
6+
use PhpOffice\PhpSpreadsheet\Shared\File;
7+
use PHPUnit\Framework\TestCase;
8+
9+
class Issue4521Test extends TestCase
10+
{
11+
private string $outfile = '';
12+
13+
protected int $weirdMimetypeMajor = 8;
14+
15+
protected int $weirdMimetypeMinor1 = 1;
16+
17+
protected int $weirdMimetypeMinor2 = 2;
18+
19+
protected function tearDown(): void
20+
{
21+
if ($this->outfile !== '') {
22+
unlink($this->outfile);
23+
$this->outfile = '';
24+
}
25+
}
26+
27+
public function testEmptyFile(): void
28+
{
29+
$this->outfile = File::temporaryFilename();
30+
file_put_contents($this->outfile, '');
31+
$spreadsheet = IOFactory::load($this->outfile);
32+
$sheet = $spreadsheet->getActiveSheet();
33+
self::assertSame('A', $sheet->getHighestColumn());
34+
self::assertSame(1, $sheet->getHighestRow());
35+
$spreadsheet->disconnectWorksheets();
36+
}
37+
38+
public function testCrlfFile(): void
39+
{
40+
if (PHP_MAJOR_VERSION === $this->weirdMimetypeMajor) {
41+
if (
42+
PHP_MINOR_VERSION === $this->weirdMimetypeMinor1
43+
|| PHP_MINOR_VERSION === $this->weirdMimetypeMinor2
44+
) {
45+
self::markTestSkipped('Php mimetype bug with this release');
46+
}
47+
}
48+
$this->outfile = File::temporaryFilename();
49+
file_put_contents($this->outfile, "\r\n");
50+
$spreadsheet = IOFactory::load($this->outfile);
51+
$sheet = $spreadsheet->getActiveSheet();
52+
self::assertSame('A', $sheet->getHighestColumn());
53+
self::assertSame(1, $sheet->getHighestRow());
54+
$spreadsheet->disconnectWorksheets();
55+
}
56+
}

0 commit comments

Comments
 (0)