forked from PHPOffice/PhpSpreadsheet
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Security Patch Control characters should not be allowed in protocol. * Tighten Up Drawing * Fix Test
- Loading branch information
Showing
5 changed files
with
111 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
|
||
use PhpOffice\PhpSpreadsheet\Exception as SpreadsheetException; | ||
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class HtmlImage2Test extends TestCase | ||
|
@@ -49,11 +50,11 @@ public function testCantInsertImageNotFound(): void | |
self::assertCount(0, $drawingCollection); | ||
} | ||
|
||
public function testCannotInsertImageBadProtocol(): void | ||
#[DataProvider('providerBadProtocol')] | ||
public function testCannotInsertImageBadProtocol(string $imagePath): void | ||
{ | ||
$this->expectException(SpreadsheetException::class); | ||
$this->expectExceptionMessage('Invalid protocol for linked drawing'); | ||
$imagePath = 'httpx://phpspreadsheet.readthedocs.io/en/latest/topics/images/01-03-filter-icon-1.png'; | ||
$html = '<table> | ||
<tr> | ||
<td><img src="' . $imagePath . '" alt="test image voilà"></td> | ||
|
@@ -62,4 +63,17 @@ public function testCannotInsertImageBadProtocol(): void | |
$filename = HtmlHelper::createHtml($html); | ||
HtmlHelper::loadHtmlIntoSpreadsheet($filename, true); | ||
} | ||
|
||
public static function providerBadProtocol(): array | ||
{ | ||
return [ | ||
'unknown protocol' => ['httpx://example.com/image.png'], | ||
'embedded whitespace' => ['ht tp://example.com/image.png'], | ||
'control character' => ["\x14http://example.com/image.png"], | ||
'mailto' => ['mailto:[email protected]'], | ||
'mailto whitespace' => ['mail to:[email protected]'], | ||
'phar' => ['phar://example.com/image.phar'], | ||
'phar control' => ["\x14phar://example.com/image.phar"], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?xml version="1.0"?> | ||
<?mso-application progid="Excel.Sheet"?> | ||
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" | ||
xmlns:o="urn:schemas-microsoft-com:office:office" | ||
xmlns:x="urn:schemas-microsoft-com:office:excel" | ||
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" | ||
xmlns:html="http://www.w3.org/TR/REC-html40"> | ||
<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office"> | ||
<Author>author</Author> | ||
<LastAuthor>author</LastAuthor> | ||
<Created>2015-06-05T18:19:34Z</Created> | ||
<LastSaved>2024-12-25T10:16:07Z</LastSaved> | ||
<Version>16.00</Version> | ||
</DocumentProperties> | ||
<OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office"> | ||
<AllowPNG/> | ||
</OfficeDocumentSettings> | ||
<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel"> | ||
<WindowHeight>11020</WindowHeight> | ||
<WindowWidth>19420</WindowWidth> | ||
<WindowTopX>32767</WindowTopX> | ||
<WindowTopY>32767</WindowTopY> | ||
<ProtectStructure>False</ProtectStructure> | ||
<ProtectWindows>False</ProtectWindows> | ||
</ExcelWorkbook> | ||
<Styles> | ||
<Style ss:ID="Default" ss:Name="Normal"> | ||
<Alignment ss:Vertical="Bottom"/> | ||
<Borders/> | ||
<Font ss:FontName="Calibri" x:Family="Swiss" ss:Size="11" ss:Color="#000000"/> | ||
<Interior/> | ||
<NumberFormat/> | ||
<Protection/> | ||
</Style> | ||
<Style ss:ID="s16"> | ||
<NumberFormat ss:Format="General Date"/> | ||
</Style> | ||
</Styles> | ||
<Worksheet ss:Name="Лист1"> | ||
<Table ss:ExpandedColumnCount="2" ss:ExpandedRowCount="6" x:FullColumns="1" | ||
x:FullRows="1" ss:DefaultRowHeight="14.5"> | ||
<Column ss:AutoFitWidth="0" ss:Width="194"/> | ||
<Row> | ||
<Cell ss:Formula="=HYPERLINK (CHAR(20) & "j" & CHAR(13) & "avascript:alert(1)")"><Data ss:Type="String"></Data></Cell> | ||
</Row> | ||
</Table> | ||
<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel"> | ||
<PageSetup> | ||
<Header x:Margin="0.3"/> | ||
<Footer x:Margin="0.3"/> | ||
<PageMargins x:Bottom="0.75" x:Left="0.7" x:Right="0.7" x:Top="0.75"/> | ||
</PageSetup> | ||
<Selected/> | ||
<TopRowVisible>1</TopRowVisible> | ||
<Panes> | ||
<Pane> | ||
<Number>3</Number> | ||
<ActiveRow>6</ActiveRow> | ||
</Pane> | ||
</Panes> | ||
<ProtectObjects>False</ProtectObjects> | ||
<ProtectScenarios>False</ProtectScenarios> | ||
</WorksheetOptions> | ||
</Worksheet> | ||
</Workbook> |