1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
use strict;
use Test::More (tests => 117);
use_ok('HTML::Template');
while (<DATA>) {
chomp;
next if /^$/;
next if /^#/;
my ($text, $given, $wanted) = split /\|/;
my $template = HTML::Template->new(
scalarref => \$text,
default_escape => "HTML"
);
undef $given if $given eq 'undef';
$template->param(foo => $given);
my $output = $template->output;
is($output, $wanted, $text);
}
# use pipe as the seperator between fields.
# the TMPL_VAR name should always be 'foo'
# fields: TMPL_VAR|given string|escaped string
__DATA__
# use default escaping
<TMPL_VAR foo>|<b>this is bold\n|<b>this is bold\n
<TMPL_VAR name=foo>|<b>this is bold\n|<b>this is bold\n
<TMPL_VAR name='foo'>|<b>this is bold\n|<b>this is bold\n
<TMPL_VAR NAME="foo">|<b>this is bold\n|<b>this is bold\n
<!-- TMPL_VAR foo -->|<b>this is bold\n|<b>this is bold\n
<!-- TMPL_VAR name=foo -->|<b>this is bold\n|<b>this is bold\n
<!-- TMPL_VAR NAME=foo -->|<b>this is bold\n|<b>this is bold\n
<!-- TMPL_VAR name='foo' -->|<b>this is bold\n|<b>this is bold\n
<!-- TMPL_VAR NAME="foo" -->|<b>this is bold\n|<b>this is bold\n
# use js escaping
<TMPL_VAR foo ESCAPE=JS>|<b>this is bold\n|<b>this is bold\\n
<TMPL_VAR ESCAPE=JS foo>|<b>this is bold\n|<b>this is bold\\n
<TMPL_VAR ESCAPE="JS" foo>|<b>this is bold\n|<b>this is bold\\n
<TMPL_VAR foo ESCAPE="JS">|<b>this is bold\n|<b>this is bold\\n
<TMPL_VAR NAME="foo" ESCAPE="JS">|<b>this is bold\n|<b>this is bold\\n
<TMPL_VAR ESCAPE="JS" NAME="foo">|<b>this is bold\n|<b>this is bold\\n
<TMPL_VAR ESCAPE='JS' foo>|<b>this is bold\n|<b>this is bold\\n
<TMPL_VAR foo ESCAPE='JS'>|<b>this is bold\n|<b>this is bold\\n
<TMPL_VAR NAME='foo' ESCAPE='JS'>|<b>this is bold\n|<b>this is bold\\n
<TMPL_VAR ESCAPE='JS' NAME='foo'>|<b>this is bold\n|<b>this is bold\\n
<!-- TMPL_VAR foo ESCAPE=JS -->|<b>this is bold\n|<b>this is bold\\n
<!-- TMPL_VAR ESCAPE=JS foo -->|<b>this is bold\n|<b>this is bold\\n
<!-- TMPL_VAR foo ESCAPE=JS -->|<b>this is bold\n|<b>this is bold\\n
<!-- TMPL_VAR ESCAPE="JS" foo -->|<b>this is bold\n|<b>this is bold\\n
<!-- TMPL_VAR foo ESCAPE="JS" -->|<b>this is bold\n|<b>this is bold\\n
<!-- TMPL_VAR NAME="foo" ESCAPE="JS" -->|<b>this is bold\n|<b>this is bold\\n
<!-- TMPL_VAR ESCAPE="JS" NAME="foo" -->|<b>this is bold\n|<b>this is bold\\n
<!-- TMPL_VAR ESCAPE='JS' foo -->|<b>this is bold\n|<b>this is bold\\n
<!-- TMPL_VAR foo ESCAPE='JS' -->|<b>this is bold\n|<b>this is bold\\n
<!-- TMPL_VAR NAME='foo' ESCAPE='JS' -->|<b>this is bold\n|<b>this is bold\\n
<!-- TMPL_VAR ESCAPE='JS' NAME='foo' -->|<b>this is bold\n|<b>this is bold\\n
#use url escaping
<TMPL_VAR foo ESCAPE=URL>|<b>this is bold\n|%3Cb%3Ethis%20is%20bold%5Cn
<TMPL_VAR ESCAPE=URL foo>|<b>this is bold\n|%3Cb%3Ethis%20is%20bold%5Cn
<TMPL_VAR foo ESCAPE=URL>|<b>this is bold\n|%3Cb%3Ethis%20is%20bold%5Cn
<TMPL_VAR ESCAPE="URL" foo>|<b>this is bold\n|%3Cb%3Ethis%20is%20bold%5Cn
<TMPL_VAR foo ESCAPE="URL">|<b>this is bold\n|%3Cb%3Ethis%20is%20bold%5Cn
<TMPL_VAR NAME="foo" ESCAPE="URL">|<b>this is bold\n|%3Cb%3Ethis%20is%20bold%5Cn
<TMPL_VAR ESCAPE="URL" NAME="foo">|<b>this is bold\n|%3Cb%3Ethis%20is%20bold%5Cn
<TMPL_VAR ESCAPE='URL' foo>|<b>this is bold\n|%3Cb%3Ethis%20is%20bold%5Cn
<TMPL_VAR foo ESCAPE='URL'>|<b>this is bold\n|%3Cb%3Ethis%20is%20bold%5Cn
<TMPL_VAR NAME='foo' ESCAPE='URL'>|<b>this is bold\n|%3Cb%3Ethis%20is%20bold%5Cn
<TMPL_VAR ESCAPE='URL' NAME='foo'>|<b>this is bold\n|%3Cb%3Ethis%20is%20bold%5Cn
<!-- TMPL_VAR foo ESCAPE=URL -->|<b>this is bold\n|%3Cb%3Ethis%20is%20bold%5Cn
<!-- TMPL_VAR ESCAPE=URL foo -->|<b>this is bold\n|%3Cb%3Ethis%20is%20bold%5Cn
<!-- TMPL_VAR foo ESCAPE=URL -->|<b>this is bold\n|%3Cb%3Ethis%20is%20bold%5Cn
<!-- TMPL_VAR ESCAPE="URL" foo -->|<b>this is bold\n|%3Cb%3Ethis%20is%20bold%5Cn
<!-- TMPL_VAR foo ESCAPE="URL" -->|<b>this is bold\n|%3Cb%3Ethis%20is%20bold%5Cn
<!-- TMPL_VAR NAME="foo" ESCAPE="URL" -->|<b>this is bold\n|%3Cb%3Ethis%20is%20bold%5Cn
<!-- TMPL_VAR ESCAPE="URL" NAME="foo" -->|<b>this is bold\n|%3Cb%3Ethis%20is%20bold%5Cn
<!-- TMPL_VAR ESCAPE='URL' foo -->|<b>this is bold\n|%3Cb%3Ethis%20is%20bold%5Cn
<!-- TMPL_VAR foo ESCAPE='URL' -->|<b>this is bold\n|%3Cb%3Ethis%20is%20bold%5Cn
<!-- TMPL_VAR NAME='foo' ESCAPE='URL' -->|<b>this is bold\n|%3Cb%3Ethis%20is%20bold%5Cn
<!-- TMPL_VAR ESCAPE='URL' NAME='foo' -->|<b>this is bold\n|%3Cb%3Ethis%20is%20bold%5Cn
# no escaping
<TMPL_VAR foo ESCAPE=0>|<b>this is bold\n|<b>this is bold\n
<TMPL_VAR ESCAPE=0 foo>|<b>this is bold\n|<b>this is bold\n
<TMPL_VAR foo ESCAPE=0>|<b>this is bold\n|<b>this is bold\n
<TMPL_VAR ESCAPE="0" foo>|<b>this is bold\n|<b>this is bold\n
<TMPL_VAR foo ESCAPE="0">|<b>this is bold\n|<b>this is bold\n
<TMPL_VAR NAME="foo" ESCAPE="0">|<b>this is bold\n|<b>this is bold\n
<TMPL_VAR ESCAPE="0" NAME="foo">|<b>this is bold\n|<b>this is bold\n
<TMPL_VAR ESCAPE='0' foo>|<b>this is bold\n|<b>this is bold\n
<TMPL_VAR foo ESCAPE='0'>|<b>this is bold\n|<b>this is bold\n
<TMPL_VAR NAME='foo' ESCAPE='0'>|<b>this is bold\n|<b>this is bold\n
<TMPL_VAR ESCAPE='0' NAME='foo'>|<b>this is bold\n|<b>this is bold\n
<!-- TMPL_VAR foo ESCAPE=0 -->|<b>this is bold\n|<b>this is bold\n
<!-- TMPL_VAR ESCAPE=0 foo -->|<b>this is bold\n|<b>this is bold\n
<!-- TMPL_VAR foo ESCAPE=0 -->|<b>this is bold\n|<b>this is bold\n
<!-- TMPL_VAR ESCAPE="0" foo -->|<b>this is bold\n|<b>this is bold\n
<!-- TMPL_VAR foo ESCAPE="0" -->|<b>this is bold\n|<b>this is bold\n
<!-- TMPL_VAR NAME="foo" ESCAPE="0" -->|<b>this is bold\n|<b>this is bold\n
<!-- TMPL_VAR ESCAPE="0" NAME="foo" -->|<b>this is bold\n|<b>this is bold\n
<!-- TMPL_VAR ESCAPE='0' foo -->|<b>this is bold\n|<b>this is bold\n
<!-- TMPL_VAR foo ESCAPE='0' -->|<b>this is bold\n|<b>this is bold\n
<!-- TMPL_VAR NAME='foo' ESCAPE='0' -->|<b>this is bold\n|<b>this is bold\n
<!-- TMPL_VAR ESCAPE='0' NAME='foo' -->|<b>this is bold\n|<b>this is bold\n
# no escaping
<TMPL_VAR foo ESCAPE=NONE>|<b>this is bold\n|<b>this is bold\n
<TMPL_VAR ESCAPE=NONE foo>|<b>this is bold\n|<b>this is bold\n
<TMPL_VAR foo ESCAPE=NONE>|<b>this is bold\n|<b>this is bold\n
<TMPL_VAR ESCAPE="NONE" foo>|<b>this is bold\n|<b>this is bold\n
<TMPL_VAR foo ESCAPE="NONE">|<b>this is bold\n|<b>this is bold\n
<TMPL_VAR NAME="foo" ESCAPE="NONE">|<b>this is bold\n|<b>this is bold\n
<TMPL_VAR ESCAPE="NONE" NAME="foo">|<b>this is bold\n|<b>this is bold\n
<TMPL_VAR ESCAPE='NONE' foo>|<b>this is bold\n|<b>this is bold\n
<TMPL_VAR foo ESCAPE='NONE'>|<b>this is bold\n|<b>this is bold\n
<TMPL_VAR NAME='foo' ESCAPE='NONE'>|<b>this is bold\n|<b>this is bold\n
<TMPL_VAR ESCAPE='NONE' NAME='foo'>|<b>this is bold\n|<b>this is bold\n
<!-- TMPL_VAR foo ESCAPE=NONE -->|<b>this is bold\n|<b>this is bold\n
<!-- TMPL_VAR ESCAPE=NONE foo -->|<b>this is bold\n|<b>this is bold\n
<!-- TMPL_VAR foo ESCAPE=NONE -->|<b>this is bold\n|<b>this is bold\n
<!-- TMPL_VAR ESCAPE="NONE" foo -->|<b>this is bold\n|<b>this is bold\n
<!-- TMPL_VAR foo ESCAPE="NONE" -->|<b>this is bold\n|<b>this is bold\n
<!-- TMPL_VAR NAME="foo" ESCAPE="NONE" -->|<b>this is bold\n|<b>this is bold\n
<!-- TMPL_VAR ESCAPE="NONE" NAME="foo" -->|<b>this is bold\n|<b>this is bold\n
<!-- TMPL_VAR ESCAPE='NONE' foo -->|<b>this is bold\n|<b>this is bold\n
<!-- TMPL_VAR foo ESCAPE='NONE' -->|<b>this is bold\n|<b>this is bold\n
<!-- TMPL_VAR NAME='foo' ESCAPE='NONE' -->|<b>this is bold\n|<b>this is bold\n
<!-- TMPL_VAR ESCAPE='NONE' NAME='foo' -->|<b>this is bold\n|<b>this is bold\n
#no escaping and default escaping
<TMPL_VAR foo ESCAPE=0> <TMPL_VAR foo>|<b>this is bold\n|<b>this is bold\n <b>this is bold\n
<!-- TMPL_VAR foo ESCAPE=0 --> <!-- TMPL_VAR foo -->|<b>this is bold\n|<b>this is bold\n <b>this is bold\n
# mixing escape and default
<TMPL_VAR foo default="UNKNOWN VALUE" ESCAPE=HTML>|fl<i>pper|fl<i>pper
<TMPL_VAR name="foo" default="UNKNOWN VALUE" escape="HTML">|fl<i>pper|fl<i>pper
<!-- TMPL_VAR NAME="foo" DEFAULT="UNKNOWN VALUE" ESCAPE="HTML" -->|fl<i>pper|fl<i>pper
<TMPL_VAR foo default="UNKNOWN VALUE" escape="HTML">|undef|UNKNOWN VALUE
<TMPL_VAR name="foo" default="UNKNOWN VALUE" ESCAPE='html'>|undef|UNKNOWN VALUE
<!-- TMPL_VAR NAME="foo" DEFAULT="UNKNOWN VALUE" ESCAPE="html" -->|undef|UNKNOWN VALUE
<TMPL_VAR foo ESCAPE=html default="UNKNOWN VALUE">|fl<i>pper|fl<i>pper
<TMPL_VAR name="foo" escape="HTML" default="UNKNOWN VALUE">|fl<i>pper|fl<i>pper
<!-- TMPL_VAR NAME="foo" ESCAPE='HTML' DEFAULT="UNKNOWN VALUE" -->|fl<i>pper|fl<i>pper
<TMPL_VAR foo escape='html' default="UNKNOWN VALUE">|undef|UNKNOWN VALUE
<TMPL_VAR name="foo" ESCAPE=HTML default="UNKNOWN VALUE">|undef|UNKNOWN VALUE
<!-- TMPL_VAR NAME="foo" ESCAPE="HTML" DEFAULT="UNKNOWN VALUE" -->|undef|UNKNOWN VALUE
<TMPL_VAR ESCAPE=html default="UNKNOWN VALUE" foo>|fl<i>pper|fl<i>pper
<TMPL_VAR escape="HTML" name="foo" default="UNKNOWN VALUE">|fl<i>pper|fl<i>pper
<!-- TMPL_VAR ESCAPE='HTML' DEFAULT="UNKNOWN VALUE" NAME="foo" -->|fl<i>pper|fl<i>pper
<TMPL_VAR escape='html' foo default="UNKNOWN VALUE">|undef|UNKNOWN VALUE
<TMPL_VAR ESCAPE=HTML name="foo" default="UNKNOWN VALUE">|undef|UNKNOWN VALUE
<!-- TMPL_VAR ESCAPE="HTML" DEFAULT="UNKNOWN VALUE" name="foo" -->|undef|UNKNOWN VALUE
|