Skip Menu |

This queue is for tickets about the Template-Alloy CPAN distribution.

Report information
The Basics
Id: 76570
Status: resolved
Priority: 0/
Queue: Template-Alloy

People
Owner: Nobody in particular
Requestors: onken [...] netcubed.de
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 1.016
Fixed in: (no value)



Subject: Template::Alloy doesn't handle wide characters in a template
Unlike Template::Toolkit, Template::Alloy croaks when a wide character is in a template. Test and possible fix attached.
Subject: wide.diff
diff --git a/lib/Template/Alloy.pm b/lib/Template/Alloy.pm index 862d1fc..08aef77 100644 --- a/lib/Template/Alloy.pm +++ b/lib/Template/Alloy.pm @@ -331,12 +331,21 @@ sub load_template { } sub string_id { - my ($self, $ref) = @_; + my ( $self, $ref ) = @_; require Digest::MD5; - my $sum = Digest::MD5::md5_hex($$ref); - return 'Alloy_str_ref_cache/'.substr($sum,0,3).'/'.$sum; + my $string = ref $self # called as method on an object + && $self->{'ENCODING'} # ENCODING is defined + && eval { require Encode } # Encode.pm is available + && defined &Encode::encode + ? Encode::encode( $self->{ENCODING}, $$ref ) + : $$ref; + my $sum = Digest::MD5::md5_hex($string); + return 'Alloy_str_ref_cache/' . substr( $sum, 0, 3 ) . '/' . $sum; } + + + sub load_tree { my ($self, $doc) = @_; diff --git a/t/40_encoding.t b/t/40_encoding.t new file mode 100644 index 0000000..ece24bb --- /dev/null +++ b/t/40_encoding.t @@ -0,0 +1,30 @@ +# -*- Mode: Perl; -*- + +=head1 NAME + +04_text_tmpl.t - Test the ability to parse and play Text::Tmpl + +=cut + +use vars qw($module $is_tt $compile_perl); +BEGIN { + $module = 'Template::Alloy'; + if (grep {/tt|tmpl/i} @ARGV) { + $module = 'Text::Tmpl'; + } + $is_tt = $module eq 'Text::Tmpl'; +}; + +use strict; +use Test::More tests => 2; +use constant test_taint => 0 && eval { require Taint::Runtime }; + +use_ok($module); + +Taint::Runtime::taint_start() if test_taint; + +my $tt = $module->new( ENCODING => 'UTF8' ); +my $template = "\x{200b}"; +my $fail; +$tt->process(\$template, {}, \my $out) or $fail = $@; +ok(!$fail, 'lives ok'); \ No newline at end of file
Thank you for your patch. It was applied a little different, but the basics are there in full.