Conditions | 1 |
Paths | 1 |
Total Lines | 18 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
14 | public function testNoJavascriptLinks(): void |
||
15 | { |
||
16 | $spreadsheet = new Spreadsheet(); |
||
17 | $sheet = $spreadsheet->getActiveSheet(); |
||
18 | $sheet->getCell('A1')->setValue('Click me'); |
||
19 | $hyperlink = new Hyperlink('http://www.example.com'); |
||
20 | $sheet->getCell('A1')->setHyperlink($hyperlink); |
||
21 | $sheet->getCell('A2')->setValue('JS link'); |
||
22 | $hyperlink2 = new Hyperlink('javascript:alert(\'hello1\')'); |
||
23 | $sheet->getCell('A2')->setHyperlink($hyperlink2); |
||
24 | $sheet->getCell('A3')->setValue('=HYPERLINK("javascript:alert(\'hello2\')", "jsfunc click")'); |
||
25 | |||
26 | $writer = new Html($spreadsheet); |
||
27 | $html = $writer->generateHTMLAll(); |
||
28 | self::assertStringContainsString('<td class="column0 style0 s"><a href="http://www.example.com" title="">Click me</a></td>', $html, 'http hyperlink retained'); |
||
29 | self::assertStringContainsString('<td class="column0 style0 s">javascript:alert(\'hello1\')</td>', $html, 'javascript hyperlink dropped'); |
||
30 | self::assertStringContainsString('<td class="column0 style0 f">javascript:alert(\'hello2\')</td>', $html, 'javascript hyperlink function dropped'); |
||
31 | $spreadsheet->disconnectWorksheets(); |
||
32 | } |
||
34 |