|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Test: |noescape |
| 5 | + */ |
| 6 | + |
| 7 | +declare(strict_types=1); |
| 8 | + |
| 9 | +use Tester\Assert; |
| 10 | + |
| 11 | + |
| 12 | +require __DIR__ . '/../bootstrap.php'; |
| 13 | + |
| 14 | + |
| 15 | +$latte = new Latte\Engine; |
| 16 | +$latte->setLoader(new Latte\Loaders\StringLoader); |
| 17 | + |
| 18 | +// html text |
| 19 | +Assert::match( |
| 20 | + '<p></script></p>', |
| 21 | + $latte->renderToString('<p>{="</script>"|noescape}</p>'), |
| 22 | +); |
| 23 | + |
| 24 | +// raw text |
| 25 | +Assert::match( |
| 26 | + '<script><\/script></script>', |
| 27 | + $latte->renderToString('<script>{="</script>"|noescape}</script>'), |
| 28 | +); |
| 29 | + |
| 30 | +Assert::match( |
| 31 | + '<style><\/script></style>', |
| 32 | + $latte->renderToString('<style>{="</script>"|noescape}</style>'), |
| 33 | +); |
| 34 | + |
| 35 | +Assert::match( |
| 36 | + '<script type="text/html"><\/script></script>', |
| 37 | + $latte->renderToString('<script type="text/html">{="</script>"|noescape}</script>'), |
| 38 | +); |
| 39 | + |
| 40 | +// in tag |
| 41 | +Assert::match( |
| 42 | + '<p foo a=\'a\' b="b">></p>', |
| 43 | + $latte->renderToString('<p {="foo a=\'a\' b=\"b\">"|noescape}></p>'), |
| 44 | +); |
| 45 | + |
| 46 | +// attribute unquoted values |
| 47 | +Assert::match( |
| 48 | + '<p title=foo a=\'a\' b="b">></p>', |
| 49 | + $latte->renderToString('<p title={="foo a=\'a\' b=\"b\">"|noescape}></p>'), |
| 50 | +); |
| 51 | + |
| 52 | +// attribute quoted values |
| 53 | +Assert::match( |
| 54 | + '<p title="foo a=\'a\' b="b">"></p>', |
| 55 | + $latte->renderToString('<p title="{="foo a=\'a\' b=\"b\">"|noescape}"></p>'), |
| 56 | +); |
| 57 | + |
| 58 | +Assert::match( |
| 59 | + '<p title=\'foo a='a' b="b">\'></p>', |
| 60 | + $latte->renderToString('<p title=\'{="foo a=\'a\' b=\"b\">"|noescape}\'></p>'), |
| 61 | +); |
| 62 | + |
| 63 | +Assert::match( |
| 64 | + '<p style="foo a=\'a\' b="b">"></p>', |
| 65 | + $latte->renderToString('<p style="{="foo a=\'a\' b=\"b\">"|noescape}"></p>'), |
| 66 | +); |
| 67 | + |
| 68 | +Assert::match( |
| 69 | + '<p onclick="foo a=\'a\' b="b">"></p>', |
| 70 | + $latte->renderToString('<p onclick="{="foo a=\'a\' b=\"b\">"|noescape}"></p>'), |
| 71 | +); |
0 commit comments