Bugzilla – Bug 668
RssNews plugin crashes on Perl 5.6.1 - Undefined subroutine: utf8::decode
Last modified: 2008-12-18 11:50:32 UTC
The RssNews.pm plugin crashes when you attempt to connect to an RSS stream, with Perl v5.6.1. The crash is: Undefined subroutine utf8::decode called at /home/rbc/slim/local/slimserver/Plugins/RssNews.pm line 350 utf8::decode seems to be a Perl 5.8ism - it doesn't exist in 5.6. This happens on Debian 3.0, with the tarball of SlimServer 5.4.0
This might also be an issue for Mac OS X 10.2 and below, since they only have 5.6.0 installed. Will test on my old ibook when I get a moment...
It also uses the 5.8.0-only $n% sprintf format; once I changed both the call to utf8::decode and sprintf to work on 5.6.0 and used it as a screensaver, it locked up the UI and just kept showing little blips of RSS - no buttons on the remote worked. I'd suggest either someone who knows how RssNews *works* look at this with 5.6.0, or just put "use 5.8.0;" in so that it won't load and fool us poor 5.6 users into trying it. ("use utf8" says that the source code is going to use UTF-8 encoding; since there are no UTF-8 bytes in the source code, the "use utf8" lines are extraneous)
Regarding Bill Fenner's comment about the "use utf8" being unnecessary. Actually it is necessary to make the regexps behave nicely even though there are no utf8 chars in the code itself. Believe me I wanted to get rid of that troublesome stuff. As for looking at it with perl 5.6, you are absolutely right. I will get on that.
this is what i did to get it to work on 5.6.1: all changes are done in /usr/local/slimserver/Plugins/RssNews.pm. i installed the Text::Iconv module and the Encode::compat module. i then made this change around line 350 (the line below the get rid of urls is not really a related fix, i just find urls in rss feeds on the slimp3 annoying): sub unescapeAndTrim { my $data = shift; return '' unless(defined($data)); use utf8; # required for 5.6 my $olddata = $data; # get rid of urls $data =~ s/<[^>]*>//g; $data = unescape($data); $data = trim($data); use Encode::compat; use Encode; Encode::decode("utf-8", $data); #utf8::decode($data); #$::d_plugins && msg("old text: \"$olddata\"\n\n"); #$::d_plugins && msg("new text: \"$data\"\n\n\n"); return $data; } that moved the problem. there's a sprintf that perl 5.6.1 doesn't like and gets all pissy about. so that required a change to line 40 (the commented line is the original): #my $screensaver_item_format = "%2\$s -- %3\$s "; my $screensaver_item_format = "\%s -- \%s "; and then down near line 621 (that's not exact since i added lines in the first fix) i commented out the second arg to the sprintf call that used $screensaver_item_format as its format: } else { $description = $thenews{$display_current}->{item}[$i]->{description}; } $line2 .= sprintf($screensaver_item_format, #$i + 1, unescapeAndTrim($thenews{$display_current}->{item}[$i]->{title}), unescapeAndTrim($description)); $i++; hope this helps!
Kevin (et al), There is a fix for this checked into the code tree, a recent build of the server will have it. The fix uses conditionals such as: if ($] >= 5.008) { utf8::decode($data); } So it should not adversely affect later versions of Perl. At some point I had tried the Encode::decode call that Kevin suggests. On my system it left some accented characters looking wrong, so I didn't use it. But if it works for you, great. I'm going to resolve this bug (I'm not sure why it wasn't resolved already), but if anyone out there has a problem with the latest version of the code please let me know, I'll open the bug back up. Thanks, -Dave
There are 536 bugs in the database with targets of '---' that were fixed prior to new year 2006. I am setting them to targets of 6.2.1 to keep them from showing up in my queries.
Routine bug db maintenance; removing old versions which cause confusion. I apologize for the inconvenience.