[Templates] Hashes: issue with UTF-8 keys
[prev]
[thread]
[next]
[Date index for 2004/10/20]
Hi,
I've found an issue with hashes when a key is a UTF-8 string.
I have some simple test code:
#!/usr/bin/env perl
use strict;
use Template;
my $tt = Template->new({ INCLUDE_PATH => '.', }) || die
"$Template::ERROR\n";
my %hash = ( 'good' => 1234, "bad \x{20AC}" => 4321, );
my $vars = {
hash => \%hash,
};
$tt->process('template.tt', $vars) || die $tt->error(), "\n";
template.txt:
Start [% component.name %]
Iterate through the hash:
[% FOREACH key = hash.keys %]
Key: [% key %] Exists: [% hash.exists(key) %] Value: [% hash.$key %]
Item: [% hash.item(key) %]
[% END %]
End [% component.name %]
With both TT 2.13 and 2.14 the output is:
Start template.tt
Iterate through the hash:
Key: good Exists: 1 Value: 1234 Item: 1234
Key: bad ⬠Exists: 1 Value: Item: 4321
End template.tt
Note that [% hash.$key %] fails for the UTF-8 key, but [% hash.item(key) %]
works (and is a workaround).
This is with Perl 5.8.4. Maybe someone can confirm it isn't a Perl problem
with a more recent version?
cheers
Dave
_______________________________________________
templates mailing list
templates@xxxxxxxxxxxxxxxx.xxx
http://lists.template-toolkit.org/mailman/listinfo/templates
 |
[Templates] Hashes: issue with UTF-8 keys
Dave Meibusch 06:23 on 20 Oct 2004
|