Changeset 1772

Show
Ignore:
Timestamp:
01/27/06 03:51:25
Author:
miyagawa
Message:

0.04: fixed double decode when templates are BOMed

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Template-Provider-Encoding/trunk/Changes

    r1769 r1772  
    11Revision history for Perl extension Template::Provider::Encoding 
     2 
     30.04  2006-01-26T18:50:22Z 
     4        - Do nothing when template is BOMed 
     5          (Thanks to Bill Moseley) 
    26 
    370.03  2006-01-16T22:38:37Z 
  • Template-Provider-Encoding/trunk/lib/Template/Provider/Encoding.pm

    r1769 r1772  
    22 
    33use strict; 
    4 our $VERSION = '0.03'; 
     4our $VERSION = '0.04'; 
    55 
    66use base qw( Template::Provider ); 
     
    1111    my($data, $error) = $self->SUPER::_load(@_); 
    1212 
    13     my $encoding = $data->{text} =~ /^\[% USE encoding '([\w\-]+)'/ 
    14         ? $1 : 'utf-8'; 
     13    unless (Encode::is_utf8($data->{text})) { 
     14        my $encoding = $data->{text} =~ /^\[% USE encoding '([\w\-]+)'/ 
     15            ? $1 : 'utf-8'; 
     16        $data->{text} = Encode::decode($encoding, $data->{text}); 
     17    } 
    1518 
    16     $data->{text} = Encode::decode($encoding, $data->{text}); 
    1719    return ($data, $error); 
    1820} 
  • Template-Provider-Encoding/trunk/t/01_unicode.t

    r1747 r1772  
    77use Template; 
    88 
    9 my @files = qw( euc-jp.tt utf-8.tt utf-8-wo-encoding.tt ); 
     9my @files = qw( euc-jp.tt utf-8.tt utf-8-wo-encoding.tt utf-8-bom.tt ); 
    1010 
    1111my $author = "\x{5bae}\x{5ddd}"; # miyagawa 
     
    2626    like $out, qr/$author/, "$file includes author name correctly"; 
    2727    like $out, qr/$place/, "$file includes place correctly"; 
    28     unless ($file =~ /-wo-/) { 
     28    unless ($file =~ /(-wo-|-bom)/) { 
    2929        my $encoding = ($file =~ /(.*)\.tt/)[0]; 
    3030        like $out, qr/encoding=$encoding/, "$file has encoding $encoding"; 
     
    4646    like $out, qr/$author/, "$file includes author name correctly"; 
    4747    like $out, qr/$place/, "$file includes place correctly"; 
    48     unless ($file =~ /-wo-/) { 
     48    unless ($file =~ /(-wo-|-bom)/) { 
    4949        my $encoding = ($file =~ /(.*)\.tt/)[0]; 
    5050        like $out, qr/encoding=$encoding/, "$file has encoding $encoding";