Skip to content
This repository has been archived by the owner on Aug 20, 2018. It is now read-only.

Commit

Permalink
DOMDocument: remove script tags from DOM (TPresenter)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtnzlml committed Jul 24, 2016
1 parent bfb65ac commit 5134803
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/Traits/TPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ protected function checkAction($destination, $params = [], $post = [])
Assert::type('Nette\Application\UI\ITemplate', $response->getSource());

$html = (string)$response->getSource();
//DOMDocument doesn't handle HTML tags inside of script tags very well
$html = preg_replace('~<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>~', '', $html); //http://stackoverflow.com/a/6660315/3135248
$dom = \Tester\DomQuery::fromHtml($html);
Assert::true($dom->has('html'), "missing 'html' tag");
Assert::true($dom->has('title'), "missing 'title' tag");
Expand Down
7 changes: 3 additions & 4 deletions tests/Traits/TPresenterTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ class TPresenterTest extends \Testbench\CustomPresenterTestCase
{
$this->checkAction('Presenter:default');

//FIXME: how to?
//Assert::error(function () {
// $this->checkAction('Presenter:variabledoesntexist');
//}, E_NOTICE, 'Undefined variable: doesnexist');
Assert::error(function () {
$this->checkAction('Presenter:variabledoesntexist');
}, E_NOTICE, 'Undefined variable: doesnexist');
}

public function testClassicRenderShort()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<title>TEST</title>
</head>
<body>
<div>
<script>
{$doesnexist}
</div>
</script>
</body>
</html>

0 comments on commit 5134803

Please sign in to comment.