Skip to content

Commit 90162a1

Browse files
authored
Merge branch 'master' into amordegrc
2 parents a0f811f + 63ccb02 commit 90162a1

File tree

9 files changed

+57
-6
lines changed

9 files changed

+57
-6
lines changed

src/PhpSpreadsheet/Helper/Sample.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use PhpOffice\PhpSpreadsheet\Spreadsheet;
1010
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
1111
use PhpOffice\PhpSpreadsheet\Writer\IWriter;
12+
use PhpOffice\PhpSpreadsheet\Writer\Pdf\Dompdf;
1213
use RecursiveDirectoryIterator;
1314
use RecursiveIteratorIterator;
1415
use RecursiveRegexIterator;
@@ -125,7 +126,11 @@ public function write(Spreadsheet $spreadsheet, string $filename, array $writers
125126
$writerCallback($writer);
126127
}
127128
$callStartTime = microtime(true);
128-
$writer->save($path);
129+
if (PHP_VERSION_ID >= 80400 && $writer instanceof Dompdf) {
130+
@$writer->save($path);
131+
} else {
132+
$writer->save($path);
133+
}
129134
$this->logWrite($writer, $path, $callStartTime);
130135
if ($this->isCli() === false) {
131136
// @codeCoverageIgnoreStart

src/PhpSpreadsheet/Reader/Security/XmlScanner.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ private function toUtf8(string $xml): string
5151
private function findCharSet(string $xml): string
5252
{
5353
$patterns = [
54-
'/encoding="([^"]*]?)"/',
55-
"/encoding='([^']*?)'/",
54+
'/encoding\\s*=\\s*"([^"]*]?)"/',
55+
"/encoding\\s*=\\s*'([^']*?)'/",
5656
];
5757

5858
foreach ($patterns as $pattern) {

tests/PhpSpreadsheetTests/Functional/StreamTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
use PhpOffice\PhpSpreadsheet\Spreadsheet;
99
use PHPUnit\Framework\TestCase;
1010

11+
/**
12+
* Not clear that Dompdf will be Php8.4 compatible in time.
13+
* Run in separate process and add version test till it is ready.
14+
*
15+
* @runTestsInSeparateProcesses
16+
*/
1117
class StreamTest extends TestCase
1218
{
1319
public static function providerFormats(): array
@@ -42,7 +48,11 @@ public function testAllWritersCanWriteToStream(string $format): void
4248
} else {
4349
self::assertSame(0, $stat['size']);
4450

45-
$writer->save($stream);
51+
if ($format === 'Dompdf' && PHP_VERSION_ID >= 80400) {
52+
@$writer->save($stream);
53+
} else {
54+
$writer->save($stream);
55+
}
4656

4757
self::assertIsResource($stream, 'should not close the stream for further usage out of PhpSpreadsheet');
4858
$stat = fstat($stream);

tests/PhpSpreadsheetTests/Reader/Security/XmlScannerTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,20 @@ public function testEncodingAllowsMixedCase(): void
131131
$output = $scanner->scan($input = '<?xml version="1.0" encoding="utf-8"?><foo>bar</foo>');
132132
self::assertSame($input, $output);
133133
}
134+
135+
public function testUtf7Whitespace(): void
136+
{
137+
$this->expectException(ReaderException::class);
138+
$this->expectExceptionMessage('Double-encoded');
139+
$reader = new Xlsx();
140+
$reader->load('tests/data/Reader/XLSX/utf7white.dontuse');
141+
}
142+
143+
public function testUtf8Entity(): void
144+
{
145+
$this->expectException(ReaderException::class);
146+
$this->expectExceptionMessage('Detected use of ENTITY');
147+
$reader = new Xlsx();
148+
$reader->load('tests/data/Reader/XLSX/utf8entity.dontuse');
149+
}
134150
}

tests/PhpSpreadsheetTests/Writer/Dompdf/PaperSizeArrayTest.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
use PhpOffice\PhpSpreadsheet\Writer\Pdf\Dompdf;
1111
use PHPUnit\Framework\TestCase;
1212

13+
/**
14+
* Not clear that Dompdf will be Php8.4 compatible in time.
15+
* Run in separate process and add version test till it is ready.
16+
*
17+
* @runTestsInSeparateProcesses
18+
*/
1319
class PaperSizeArrayTest extends TestCase
1420
{
1521
private string $outfile = '';
@@ -36,7 +42,11 @@ public function testPaperSizeArray(): void
3642
$sheet->setCellValue('A7', 'Lorem Ipsum');
3743
$writer = new Dompdf($spreadsheet);
3844
$this->outfile = File::temporaryFilename();
39-
$writer->save($this->outfile);
45+
if (PHP_VERSION_ID >= 80400) { // hopefully temporary
46+
@$writer->save($this->outfile);
47+
} else {
48+
$writer->save($this->outfile);
49+
}
4050
$spreadsheet->disconnectWorksheets();
4151
unset($spreadsheet);
4252
$contents = file_get_contents($this->outfile);
@@ -56,7 +66,11 @@ public function testPaperSizeNotArray(): void
5666
$sheet->setCellValue('A7', 'Lorem Ipsum');
5767
$writer = new Dompdf($spreadsheet);
5868
$this->outfile = File::temporaryFilename();
59-
$writer->save($this->outfile);
69+
if (PHP_VERSION_ID >= 80400) { // hopefully temporary
70+
@$writer->save($this->outfile);
71+
} else {
72+
$writer->save($this->outfile);
73+
}
6074
$spreadsheet->disconnectWorksheets();
6175
unset($spreadsheet);
6276
$contents = file_get_contents($this->outfile);
8.75 KB
Binary file not shown.
8.67 KB
Binary file not shown.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding ='UTF-7' standalone="yes"?>
2+
+ADw-+ACE-DOCTYPE+ACA-foo+ACA-+AFs-+ADw-+ACE-ENTITY+ACA-toreplace+ACA-+ACI-xxe+AF8-test+ACI-+AD4-+ACA-+AF0-+AD4-+AAo-+ADw-sst+ACA-xmlns+AD0-+ACI-http://schemas.openxmlformats.org/spreadsheetml/2006/main+ACI-+ACA-count+AD0-+ACI-2+ACI-+ACA-uniqueCount+AD0-+ACI-1+ACI-+AD4-+ADw-si+AD4-+ADw-t+AD4-+ACY-toreplace+ADs-+ADw-/t+AD4-+ADw-/si+AD4-+ADw-/sst+AD4-
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version='1.0' encoding = "UTF-8" standalone='yes'?>
2+
<root>
3+
test: Valid
4+
</root>

0 commit comments

Comments
 (0)