Bug 668 - RssNews plugin crashes on Perl 5.6.1 - Undefined subroutine: utf8::decode
: RssNews plugin crashes on Perl 5.6.1 - Undefined subroutine: utf8::decode
Status: RESOLVED FIXED
Product: Logitech Media Server
Classification: Unclassified
Component: Plugins
: 5.x or older
: PC Debian Linux
: P2 normal with 1 vote (vote)
: ---
Assigned To: Dave Cohen
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2004-11-19 17:14 UTC by Robin Cooksey
Modified: 2008-12-18 11:50 UTC (History)
0 users

See Also:
Category: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Robin Cooksey 2004-11-19 17:14:10 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
Comment 1 Blackketter Dean 2004-11-20 14:19:15 UTC
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...
Comment 2 Bill Fenner 2004-11-28 09:48:50 UTC
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)

Comment 3 Dave Cohen 2004-11-28 15:40:43 UTC
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.
Comment 4 kevin lyda 2004-12-29 13:18:43 UTC
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!
Comment 5 Dave Cohen 2004-12-30 15:36:18 UTC
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
Comment 6 Chris Owens 2006-06-16 14:40:41 UTC
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.
Comment 7 Chris Owens 2008-12-18 11:50:32 UTC
Routine bug db maintenance; removing old versions which cause confusion.  I apologize for the inconvenience.