From: skaufman Date: Thu, 14 Aug 2014 11:30:25 +0000 (-0400) Subject: pass args to ::TT along to all the manually instantiated Template components. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=efe5868f17f0dffd48a7f1e3ed7198be3554af76;p=scpubgit%2FHTML-String.git pass args to ::TT along to all the manually instantiated Template components. --- diff --git a/lib/HTML/String/TT.pm b/lib/HTML/String/TT.pm index 0244de8..f132071 100644 --- a/lib/HTML/String/TT.pm +++ b/lib/HTML/String/TT.pm @@ -30,17 +30,19 @@ BEGIN { 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, ); } diff --git a/xt/tt.t b/xt/tt.t index a370a1a..9479a73 100644 --- a/xt/tt.t +++ b/xt/tt.t @@ -1,7 +1,7 @@ use strictures 1; use Test::More; use HTML::String::TT; - +plan tests => 10; my $tt = HTML::String::TT->new; sub do_tt { @@ -50,7 +50,7 @@ is( '[% FOREACH item IN items %][% item %][% END %]', { items => [ '', '-> & so "on" <-' ] } ), - '<script>alert("lalala")</script>' + '<script>alert("lalala")</script>' .'-> & so "on" <-' ); @@ -67,11 +67,24 @@ is( do_tt('"0"', {}), '"0"' ); ]; 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>', + $test_name + ); +} +_is_escaped('ANYCASE => 1 in a hash',ANYCASE => 1 ); +_is_escaped('ANYCASE => 1 in a hashref',{ ANYCASE => 1 }); done_testing;