Skip to content

Commit

Permalink
handle non-string variables in php view engine + improve view engine …
Browse files Browse the repository at this point in the history
…tests
  • Loading branch information
Jared King committed Oct 17, 2016
1 parent 5475eba commit 0e79f39
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/ViewEngine/PHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public function renderView(View $view)

// escape HTML special characters
foreach ($parameters as &$value) {
if (is_array($value) || is_object($value)) {
continue;
}

$value = htmlspecialchars($value, ENT_QUOTES, 'UTF-8', false);
}

Expand Down
5 changes: 4 additions & 1 deletion tests/ViewEngine/MustacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ public function testRenderView()

self::$engine->setGlobalParameters([
'to' => 'should_be_overwritten',
'greeting' => 'Hello', ]);
'greeting' => 'Hello',
'object' => new stdClass(),
'array' => [],
]);

$this->assertEquals("Hello, world!\n<script>console.log("hello");</script>", self::$engine->renderView($view));
}
Expand Down
7 changes: 6 additions & 1 deletion tests/ViewEngine/PHPTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ public function testGlobalParameters()

public function testRenderView()
{
$view = new View('test', ['to' => 'world', 'escape' => '<script>console.log("hello");</script>']);
$view = new View('test', [
'to' => 'world',
'escape' => '<script>console.log("hello");</script>',
'object' => new stdClass(),
'array' => [],
]);

self::$engine->setGlobalParameters([
'to' => 'should_be_overwritten',
Expand Down
7 changes: 6 additions & 1 deletion tests/ViewEngine/SmartyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ public function testGetSmarty()

public function testRenderView()
{
$view = new View('test', ['to' => 'world', 'escape' => '<script>console.log("hello");</script>']);
$view = new View('test', [
'to' => 'world',
'escape' => '<script>console.log("hello");</script>',
'object' => new stdClass(),
'array' => [],
]);

self::$engine->setGlobalParameters([
'to' => 'should_be_overwritten',
Expand Down
7 changes: 6 additions & 1 deletion tests/ViewEngine/TwigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ public function testTwig()

public function testRenderView()
{
$view = new View('test', ['to' => 'world', 'escape' => '<script>console.log("hello");</script>']);
$view = new View('test', [
'to' => 'world',
'escape' => '<script>console.log("hello");</script>',
'object' => new stdClass(),
'array' => [],
]);

self::$engine->setGlobalParameters([
'to' => 'should_be_overwritten',
Expand Down

0 comments on commit 0e79f39

Please sign in to comment.