Skip to content

Commit

Permalink
Return empty string if null is passed to escape view helper
Browse files Browse the repository at this point in the history
  • Loading branch information
leo-galleguillos committed Jul 15, 2021
1 parent 17551b0 commit 1baedec
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
8 changes: 1 addition & 7 deletions src/View/Helper/Escape.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@ public function __construct(
$this->escapeService = $escapeService;
}

/**
* Invoke.
*
* @param string $string
* @return string
*/
public function __invoke(string $string) : string
public function __invoke(string $string = null): string
{
return $this->escapeService->escape($string);
}
Expand Down
13 changes: 5 additions & 8 deletions test/View/Helper/EscapeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ protected function setUp(): void
);
}

public function testInitialize()
{
$this->assertInstanceOf(
StringHelper\Escape::class,
$this->escapeHelper
);
}

public function testInvoke()
{
$this->assertSame(
Expand All @@ -41,5 +33,10 @@ public function testInvoke()
'">attempt injection after attribute',
$this->escapeHelper->__invoke($string)
);

$this->assertSame(
'',
$this->escapeHelper->__invoke(null)
);
}
}

0 comments on commit 1baedec

Please sign in to comment.