Skip to content

Commit 63ccb02

Browse files
authored
Merge commit from fork
* Check for Whitespace Around Xml Encoding * More Tests
1 parent 3815843 commit 63ccb02

File tree

6 files changed

+24
-2
lines changed

6 files changed

+24
-2
lines changed

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/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
}
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)