diff options
author | Kevin Chabowski <kevin@kch42.de> | 2015-04-13 22:35:27 +0200 |
---|---|---|
committer | Kevin Chabowski <kevin@kch42.de> | 2015-04-13 22:35:27 +0200 |
commit | f744b3227b116d4f7ccd7c71f8b8498ebf86d85f (patch) | |
tree | 87a2ea0047c7587375986d3b1a2a31c05e8d36ce /tests | |
parent | 6d1c13b05d16e89268403860e47743455ea0a2ff (diff) | |
download | ste-f744b3227b116d4f7ccd7c71f8b8498ebf86d85f.tar.gz ste-f744b3227b116d4f7ccd7c71f8b8498ebf86d85f.tar.bz2 ste-f744b3227b116d4f7ccd7c71f8b8498ebf86d85f.zip |
Implemented autoescaping
Still needs some cleanup and documentation.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_autoescape/.gitignore | 3 | ||||
-rw-r--r-- | tests/test_autoescape/code.php | 14 | ||||
-rw-r--r-- | tests/test_autoescape/test.tpl | 29 | ||||
-rw-r--r-- | tests/test_autoescape/want | 25 |
4 files changed, 71 insertions, 0 deletions
diff --git a/tests/test_autoescape/.gitignore b/tests/test_autoescape/.gitignore new file mode 100644 index 0000000..de2a41b --- /dev/null +++ b/tests/test_autoescape/.gitignore @@ -0,0 +1,3 @@ +have +*.ast +*.transc.php diff --git a/tests/test_autoescape/code.php b/tests/test_autoescape/code.php new file mode 100644 index 0000000..4f7c998 --- /dev/null +++ b/tests/test_autoescape/code.php @@ -0,0 +1,14 @@ +<?php + +use kch42\ste\STECore; + +function test_func($ste) { + $ste->vars['test'] = 'foo"&<bar>'; + + $ste->register_tag('echoarg', function ($ste, $params, $sub) { + return $params['echo']; + }); + + // Autoescaping enabled by default + $ste->escape_method = STECore::ESCAPE_HTML; +} diff --git a/tests/test_autoescape/test.tpl b/tests/test_autoescape/test.tpl new file mode 100644 index 0000000..9452972 --- /dev/null +++ b/tests/test_autoescape/test.tpl @@ -0,0 +1,29 @@ +outer 1: $test +escaped outer 1: <ste:escape>$test</ste:escape> +double escaped outer 1: <ste:escape><ste:escape>$test</ste:escape></ste:escape> +raw outer 1: <ste:raw>$test</ste:raw> +arg outer 1: <ste:echoarg echo="$test" /> +<ste:autoescape mode="none"> +nested 1: $test +escaped nested 1: <ste:escape>$test</ste:escape> +double escaped nested 1: <ste:escape><ste:escape>$test</ste:escape></ste:escape> +raw nested 1: <ste:raw>$test</ste:raw> +arg nested 1: <ste:echoarg echo="$test" /> +<ste:autoescape mode="html"> +innermost: $test +escaped innermost: <ste:escape>$test</ste:escape> +double escaped innermost: <ste:escape><ste:escape>$test</ste:escape></ste:escape> +raw innermost: <ste:raw>$test</ste:raw> +arg innermost: <ste:echoarg echo="$test" /> +</ste:autoescape> +nested 2: $test +escaped nested 2: <ste:escape>$test</ste:escape> +double escaped nested 2: <ste:escape><ste:escape>$test</ste:escape></ste:escape> +raw nested 2: <ste:raw>$test</ste:raw> +arg nested 2: <ste:echoarg echo="$test" /> +</ste:autoescape> +outer 2: $test +escaped outer 2: <ste:escape>$test</ste:escape> +double escaped outer 2: <ste:escape><ste:escape>$test</ste:escape></ste:escape> +raw outer 2: <ste:raw>$test</ste:raw> +arg outer 2: <ste:echoarg echo="$test" /> diff --git a/tests/test_autoescape/want b/tests/test_autoescape/want new file mode 100644 index 0000000..0d06d44 --- /dev/null +++ b/tests/test_autoescape/want @@ -0,0 +1,25 @@ +outer 1: foo"&<bar> +escaped outer 1: foo"&<bar> +double escaped outer 1: foo&quot;&amp;&lt;bar&gt; +raw outer 1: foo"&<bar> +arg outer 1: foo"&<bar> +nested 1: foo"&<bar> +escaped nested 1: foo"&<bar> +double escaped nested 1: foo&quot;&amp;&lt;bar&gt; +raw nested 1: foo"&<bar> +arg nested 1: foo"&<bar> +innermost: foo"&<bar> +escaped innermost: foo"&<bar> +double escaped innermost: foo&quot;&amp;&lt;bar&gt; +raw innermost: foo"&<bar> +arg innermost: foo"&<bar> +nested 2: foo"&<bar> +escaped nested 2: foo"&<bar> +double escaped nested 2: foo&quot;&amp;&lt;bar&gt; +raw nested 2: foo"&<bar> +arg nested 2: foo"&<bar> +outer 2: foo"&<bar> +escaped outer 2: foo"&<bar> +double escaped outer 2: foo&quot;&amp;&lt;bar&gt; +raw outer 2: foo"&<bar> +arg outer 2: foo"&<bar> |