aboutsummaryrefslogtreecommitdiffstats
path: root/t/template.t
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2019-11-26 17:09:56 +0000
committerMatthew Somerville <matthew@mysociety.org>2019-12-09 09:38:03 +0000
commit6c2d3d5a7d84521d34daa2cf7e4be76a54b3b0e0 (patch)
tree75ef8cd6e1df444572ae5ec3a4048e6c3366a088 /t/template.t
parenta4290acdff6781979cc3cd7c0142d553236e5666 (diff)
Switch to default-escaped in templates.
This means any variable used in a template is automatically HTML-escaped, unless it is marked as safe either in code by using a SafeString, or in the template with the `mark_safe` function or the `safe` filter.
Diffstat (limited to 't/template.t')
-rw-r--r--t/template.t33
1 files changed, 33 insertions, 0 deletions
diff --git a/t/template.t b/t/template.t
new file mode 100644
index 000000000..1763a7f12
--- /dev/null
+++ b/t/template.t
@@ -0,0 +1,33 @@
+use FixMyStreet::Test;
+
+use_ok 'FixMyStreet::Template';
+
+my $tt = FixMyStreet::Template->new;
+
+my $output = '';
+$tt->process(\'[% s %] [% s | safe %] [% s | upper %] [% s | html %]', {
+ s => 'sp<i>l</i>it'
+}, \$output);
+is $output, 'sp&lt;i&gt;l&lt;/i&gt;it sp<i>l</i>it SP&lt;I&gt;L&lt;/I&gt;IT sp&lt;i&gt;l&lt;/i&gt;it';
+
+$output = '';
+$tt->process(\'[% s | html_para %]', { s => 'sp<i>l</i>it' }, \$output);
+is $output, "<p>\nsp&lt;i&gt;l&lt;/i&gt;it</p>\n";
+
+$output = '';
+$tt->process(\'[% loc("s") %] [% loc("s") | html_para %]', {}, \$output);
+is $output, "s <p>\ns</p>\n";
+
+$output = '';
+$tt->process(\'[% s.upper %] [% t = s %][% t %] [% t.upper %]', {
+ s => 'sp<i>l</i>it'
+}, \$output);
+is $output, 'SP&lt;I&gt;L&lt;/I&gt;IT sp&lt;i&gt;l&lt;/i&gt;it SP&lt;I&gt;L&lt;/I&gt;IT';
+
+$output = '';
+$tt->process(\'H: [% s.split(":").join(",") %]', {
+ s => '1:sp<i>l</i>it:3'
+}, \$output);
+is $output, 'H: 1,sp&lt;i&gt;l&lt;/i&gt;it,3';
+
+done_testing;