From f744b3227b116d4f7ccd7c71f8b8498ebf86d85f Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Mon, 13 Apr 2015 22:35:27 +0200 Subject: Implemented autoescaping Still needs some cleanup and documentation. --- tests/test_autoescape/.gitignore | 3 +++ tests/test_autoescape/code.php | 14 ++++++++++++++ tests/test_autoescape/test.tpl | 29 +++++++++++++++++++++++++++++ tests/test_autoescape/want | 25 +++++++++++++++++++++++++ 4 files changed, 71 insertions(+) create mode 100644 tests/test_autoescape/.gitignore create mode 100644 tests/test_autoescape/code.php create mode 100644 tests/test_autoescape/test.tpl create mode 100644 tests/test_autoescape/want (limited to 'tests') 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 @@ +vars['test'] = 'foo"&'; + + $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: $test +double escaped outer 1: $test +raw outer 1: $test +arg outer 1: + +nested 1: $test +escaped nested 1: $test +double escaped nested 1: $test +raw nested 1: $test +arg nested 1: + +innermost: $test +escaped innermost: $test +double escaped innermost: $test +raw innermost: $test +arg innermost: + +nested 2: $test +escaped nested 2: $test +double escaped nested 2: $test +raw nested 2: $test +arg nested 2: + +outer 2: $test +escaped outer 2: $test +double escaped outer 2: $test +raw outer 2: $test +arg outer 2: 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"& +arg outer 1: foo"& +nested 1: foo"& +escaped nested 1: foo"&<bar> +double escaped nested 1: foo&quot;&amp;&lt;bar&gt; +raw nested 1: foo"& +arg nested 1: foo"& +innermost: foo"&<bar> +escaped innermost: foo"&<bar> +double escaped innermost: foo&quot;&amp;&lt;bar&gt; +raw innermost: foo"& +arg innermost: foo"& +nested 2: foo"& +escaped nested 2: foo"&<bar> +double escaped nested 2: foo&quot;&amp;&lt;bar&gt; +raw nested 2: foo"& +arg nested 2: foo"& +outer 2: foo"&<bar> +escaped outer 2: foo"&<bar> +double escaped outer 2: foo&quot;&amp;&lt;bar&gt; +raw outer 2: foo"& +arg outer 2: foo"& -- cgit v1.2.3-70-g09d2