-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Html Writer Validate Hyperlink Protocols
- Loading branch information
Showing
2 changed files
with
41 additions
and
1 deletion.
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
33 changes: 33 additions & 0 deletions
33
tests/PhpSpreadsheetTests/Writer/Html/NoJavascriptLinksTest.php
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,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpOffice\PhpSpreadsheetTests\Writer\Html; | ||
|
||
use PhpOffice\PhpSpreadsheet\Cell\Hyperlink; | ||
use PhpOffice\PhpSpreadsheet\Spreadsheet; | ||
use PhpOffice\PhpSpreadsheet\Writer\Html; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class NoJavascriptLinksTest extends TestCase | ||
{ | ||
public function testNoJavascriptLinks(): void | ||
{ | ||
$spreadsheet = new Spreadsheet(); | ||
$sheet = $spreadsheet->getActiveSheet(); | ||
$sheet->getCell('A1')->setValue('Click me'); | ||
$hyperlink = new Hyperlink('http://www.example.com'); | ||
$sheet->getCell('A1')->setHyperlink($hyperlink); | ||
$sheet->getCell('A2')->setValue('JS link'); | ||
$hyperlink2 = new Hyperlink('javascript:alert(\'hello1\')'); | ||
$sheet->getCell('A2')->setHyperlink($hyperlink2); | ||
$sheet->getCell('A3')->setValue('=HYPERLINK("javascript:alert(\'hello2\')", "jsfunc click")'); | ||
|
||
$writer = new Html($spreadsheet); | ||
$html = $writer->generateHTMLAll(); | ||
self::assertStringContainsString('<td class="column0 style0 s"><a href="http://www.example.com" title="">Click me</a></td>', $html, 'http hyperlink retained'); | ||
self::assertStringContainsString('<td class="column0 style0 s">javascript:alert(\'hello1\')</td>', $html, 'javascript hyperlink dropped'); | ||
self::assertStringContainsString('<td class="column0 style0 f">javascript:alert(\'hello2\')</td>', $html, 'javascript hyperlink function dropped'); | ||
$spreadsheet->disconnectWorksheets(); | ||
} | ||
} |