Changeset 1479

Show
Ignore:
Timestamp:
08/20/06 16:30:27
Author:
miyagawa
Message:

BIG CHANGE: decode YAML from UTF-8 to Unicode when we load config files.
Fixes #103

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plagger/lib/Plagger/ConfigLoader.pm

    r1391 r1479  
    22use strict; 
    33use Carp; 
     4use Plagger::Walker; 
    45 
    56sub new { 
     
    2122    } else { 
    2223        croak "Plagger::ConfigLoader->load: $stuff: $!"; 
     24    } 
     25 
     26    unless ($config->{global} && $config->{global}->{no_decode_utf8}) { 
     27        Plagger::Walker->decode_utf8($config); 
    2328    } 
    2429 
  • trunk/plagger/lib/Plagger/Plugin/Subscription/Planet.pm

    r1173 r1479  
    88sub load { 
    99    my($self, $context) = @_; 
    10  
    11     my $keyword = $self->conf->{keyword}; 
    12        $keyword = [ $keyword ] unless ref $keyword; 
    1310 
    1411    my $lang = $self->conf->{lang} || 'default'; 
     
    2421    ); 
    2522 
    26     for my $kw (@$keyword) { 
    27         for my $site (@{ $self->{engines} }) { 
    28             my $site_url = $site; # copy 
     23    for my $site (@{ $self->{engines} }) { 
     24        my $site_url = $site; # copy 
    2925 
    30             # use eval ... die to skip if there's no url/keyword 
    31             eval { 
    32                 $site_url =~ s{{([\w\-\:]+)}}{ 
    33                     my($key, $encoding) = split /:/, $1; 
     26        # use eval ... die to skip if there's no url/keyword 
     27        eval { 
     28            $site_url =~ s{{([\w\-\:]+)}}{ 
     29                my($key, $encoding) = split /:/, $1; 
    3430 
    35                     my $data = $self->conf->{$key} or die "$key is not there"; 
    36                     if ($encoding && $encoding ne 'utf-8') { 
    37                         Encode::from_to($data, "utf-8" => $encoding); 
    38                     } 
     31                my $data = $self->conf->{$key} or die "$key is not there"; 
     32                if ($encoding && $encoding ne 'utf-8') { 
     33                    $data = Encode::encode($encoding, $data); 
     34                } else { 
     35                    $data = Encode::encode_utf8($data); 
     36                } 
    3937 
    40                     my $chunk = URI::Escape::uri_escape($data); 
    41                     $chunk =~ s/%20/+/g; # hack 
    42                     $chunk; 
    43                 }eg; 
    44                 push @{$self->conf->{feed}}, { url => $site_url } 
    45             }; 
    46         } 
     38                my $chunk = URI::Escape::uri_escape($data); 
     39                $chunk =~ s/%20/+/g; # hack 
     40                $chunk; 
     41            }eg; 
     42            push @{$self->conf->{feed}}, { url => $site_url } 
     43        }; 
    4744    } 
    4845 
  • trunk/plagger/lib/Plagger/Walker.pm

    r1389 r1479  
    1212 
    1313*isa = \&UNIVERSAL::isa; 
     14 
     15sub decode_utf8 { 
     16    my($self, $stuff) = @_; 
     17    $self = $self->new( apply_keys => 1 ) unless ref $self; 
     18    $self->apply(sub { $_[0] = Encode::decode_utf8($_[0]) unless utf8::is_utf8($_[0]) })->($stuff); 
     19} 
    1420 
    1521sub apply($&;@) { 
  • trunk/plagger/t/plugins/Filter-2chNewsokuTitle/base.t

    r1424 r1479  
    11use strict; 
     2use utf8; 
    23use t::TestPlagger; 
    3 use utf8; 
    44 
    55test_plugin_deps; 
  • trunk/plagger/t/plugins/Filter-Babelfish/babelfish.t

    r1467 r1479  
    11use strict; 
     2use utf8; 
    23use FindBin; 
    34use t::TestPlagger; 
    4 use utf8; 
    55 
    66test_plugin_deps; 
  • trunk/plagger/t/plugins/Filter-BlogPet/base.t

    r1425 r1479  
    11use strict; 
    22use t::TestPlagger; 
    3 use utf8; 
    43 
    54test_plugin_deps; 
  • trunk/plagger/t/plugins/Filter-BreakEntriesToFeeds/break.t

    r1305 r1479  
     1use utf8; 
    12use t::TestPlagger; 
    2 use utf8; 
    33 
    44plan 'no_plan'; 
  • trunk/plagger/t/plugins/Filter-GuessLanguage/guesslanguage.t

    r1283 r1479  
    22use FindBin; 
    33use t::TestPlagger; 
    4 use utf8; 
    54 
    65test_plugin_deps; 
  • trunk/plagger/t/plugins/UserAgent-RequestHeader/printenv.t

    r1307 r1479  
    11use t::TestPlagger; 
    2 use utf8; 
    32 
    43test_plugin_deps('Filter-EntryFullText', 1);