From: Caesar Date: Sat, 17 May 2014 10:49:00 +0000 (+0200) Subject: (irssi-feed) Fix issues with character sets (hackily) X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=bd4b842c94805a82b8e1e53a0ba0bd0aeb3c5c4a;p=irssi-scripts.irssi.org.git (irssi-feed) Fix issues with character sets (hackily) --- diff --git a/scripts/irssi-feed.pl b/scripts/irssi-feed.pl index 2753ba8..7bcafbd 100644 --- a/scripts/irssi-feed.pl +++ b/scripts/irssi-feed.pl @@ -290,7 +290,7 @@ sub feed_io_event_write { my $req = "GET " . $query . " HTTP/1.0\r\n" . "Host: " . $self->{uri}->host . "\r\n" . "User-Agent: Irssi feed reader " . $VERSION . "\r\n" . - "Accept-Encoding: gzip\r\n" . + "Accept-Encoding: " . HTTP::Message->decodable() . "\r\n" . "Connection: close\r\n\r\n"; $self->{io}->{conn}->send($req); Irssi::input_remove($self->{io}->{writetag}) if $self->{io}->{writetag}; @@ -337,7 +337,12 @@ sub feed_parse_buffer { } } return if not $http->is_success; - my $httpcontent = $http->decoded_content; + my $httpcontent = $http->decoded_content(); + my $contenttype = $http->header('Content-Type'); + if($contenttype and $contenttype =~ /^.*charset\s*=\s*(?[^;]*)(;|$)/ and $+{charset} !~ /UTF-8/i) { + # http specifies a non-utf8 content, but HTTP::Response will convert that to utf-8 for us. + $httpcontent =~ s/encoding\s*=\s*("[^"]*"|[^" ]*)\s(?)//; + } my $data = eval { $feed->{io}->{xml} = XML::Feed->parse(\$httpcontent) }; if($data) { $feed->{name} = $data->title;