-
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Filter |noescape preserves some escaping in some contexts
- Loading branch information
Showing
5 changed files
with
126 additions
and
3 deletions.
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
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
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
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,71 @@ | ||
<?php | ||
|
||
/** | ||
* Test: |noescape | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
use Tester\Assert; | ||
|
||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
|
||
$latte = new Latte\Engine; | ||
$latte->setLoader(new Latte\Loaders\StringLoader); | ||
|
||
// html text | ||
Assert::match( | ||
'<p></script></p>', | ||
$latte->renderToString('<p>{="</script>"|noescape}</p>'), | ||
); | ||
|
||
// raw text | ||
Assert::match( | ||
'<script><\/script></script>', | ||
$latte->renderToString('<script>{="</script>"|noescape}</script>'), | ||
); | ||
|
||
Assert::match( | ||
'<style><\/script></style>', | ||
$latte->renderToString('<style>{="</script>"|noescape}</style>'), | ||
); | ||
|
||
Assert::match( | ||
'<script type="text/html"><\/script></script>', | ||
$latte->renderToString('<script type="text/html">{="</script>"|noescape}</script>'), | ||
); | ||
|
||
// in tag | ||
Assert::match( | ||
'<p foo a=\'a\' b="b">></p>', | ||
$latte->renderToString('<p {="foo a=\'a\' b=\"b\">"|noescape}></p>'), | ||
); | ||
|
||
// attribute unquoted values | ||
Assert::match( | ||
'<p title=foo a=\'a\' b="b">></p>', | ||
$latte->renderToString('<p title={="foo a=\'a\' b=\"b\">"|noescape}></p>'), | ||
); | ||
|
||
// attribute quoted values | ||
Assert::match( | ||
'<p title="foo a=\'a\' b="b">"></p>', | ||
$latte->renderToString('<p title="{="foo a=\'a\' b=\"b\">"|noescape}"></p>'), | ||
); | ||
|
||
Assert::match( | ||
'<p title=\'foo a='a' b="b">\'></p>', | ||
$latte->renderToString('<p title=\'{="foo a=\'a\' b=\"b\">"|noescape}\'></p>'), | ||
); | ||
|
||
Assert::match( | ||
'<p style="foo a=\'a\' b="b">"></p>', | ||
$latte->renderToString('<p style="{="foo a=\'a\' b=\"b\">"|noescape}"></p>'), | ||
); | ||
|
||
Assert::match( | ||
'<p onclick="foo a=\'a\' b="b">"></p>', | ||
$latte->renderToString('<p onclick="{="foo a=\'a\' b=\"b\">"|noescape}"></p>'), | ||
); |
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,22 @@ | ||
<?php | ||
|
||
/** | ||
* Test: Latte\Runtime\Filters::escapeHtmlChar | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
use Latte\Runtime\Filters; | ||
use Tester\Assert; | ||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
|
||
Assert::same('', Filters::escapeHtmlChar(null, '"')); | ||
Assert::same('', Filters::escapeHtmlChar('', '"')); | ||
Assert::same('1', Filters::escapeHtmlChar(1, '"')); | ||
Assert::same('string', Filters::escapeHtmlChar('string', '"')); | ||
Assert::same('< & \' " >', Filters::escapeHtmlChar('< & \' " >', '"')); | ||
Assert::same('< & ' " >', Filters::escapeHtmlChar('< & \' " >', "'")); | ||
Assert::same('< & \' " >', Filters::escapeHtmlChar('< & \' " >', '>')); | ||
Assert::same('"', Filters::escapeHtmlChar('"', '"')); |