sub new {
shift;
+ my @args = (ref($_[0]) eq 'HASH' ? %{$_[0]} : @_);
Template->new(
PARSER => Template::Parser->new(
- FACTORY => 'HTML::String::TT::Directive'
+ FACTORY => 'HTML::String::TT::Directive',
+ @args,
),
- STASH => Template::Stash->new,
+ STASH => Template::Stash->new( @args,),
FILTERS => { no_escape => sub {
$_[0]->$_isa('HTML::String::Value')
? HTML::String::Value->new(map $_->[0], @{$_[0]->{parts}})
: HTML::String::Value->new($_)
} },
- (ref($_[0]) eq 'HASH' ? %{$_[0]} : @_)
+ @args,
);
}
use strictures 1;
use Test::More;
use HTML::String::TT;
-
+plan tests => 10;
my $tt = HTML::String::TT->new;
sub do_tt {
'[% FOREACH item IN items %][% item %][% END %]',
{ items => [ '<script>alert("lalala")</script>', '-> & so "on" <-' ] }
),
- '<script>alert("lalala")</script>'
+ '<script>alert("lalala")</script>'
.'-> & so "on" <-'
);
];
my $with_html_string_tt = do_tt($tmpl, {});
-
$tt = Template->new(STASH => Template::Stash->new);
my $with_template = do_tt($tmpl, {});
is $with_html_string_tt, $with_template;
}
+sub _is_escaped {
+ my $test_name = shift;
+ $tt = HTML::String::TT->new( @_ );
+ is(
+ do_tt(
+ '[%- if 1; unsafe_js; %][% end %]',
+ { unsafe_js => '<script>alert("anycase alert");</script>' }
+ ),
+ '<script>alert("anycase alert");</script>',
+ $test_name
+ );
+}
+_is_escaped('ANYCASE => 1 in a hash',ANYCASE => 1 );
+_is_escaped('ANYCASE => 1 in a hashref',{ ANYCASE => 1 });
done_testing;