Skip Menu |

This queue is for tickets about the HTML-Tree CPAN distribution.

Report information
The Basics
Id: 82538
Status: rejected
Priority: 0/
Queue: HTML-Tree

People
Owner: Nobody in particular
Requestors: HMBRAND [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 5.03
Fixed in: (no value)



Subject: Undefined arguments cause noisy parser in perl 5.16
I get loads of these: Use of uninitialized value $_[1] in lc at /pro/lib/perl5/ site_perl/5.16.0/HTML/Element.pm line 838. --8<--- --- /pro/lib/perl5/site_perl/5.16.0/HTML/Element.pm.org 2013-01-07 14:36:31.196244695 +0100 +++ /pro/lib/perl5/site_perl/5.16.0/HTML/Element.pm 2013-01-07 14:36:50.973244772 +0100 @@ -835,7 +835,7 @@ sub _fold_case_LC { map lc($_), @_; } else { - return lc( $_[1] ); + return lc( defined $_[1] ? $_[1] : "" ); } } -->8--- or, once you depend on perl-5.10 and up --8<--- --- /pro/lib/perl5/site_perl/5.16.0/HTML/Element.pm.org 2013-01-07 14:36:31.196244695 +0100 +++ /pro/lib/perl5/site_perl/5.16.0/HTML/Element.pm 2013-01-07 14:36:50.973244772 +0100 @@ -835,7 +835,7 @@ sub _fold_case_LC { map lc($_), @_; } else { - return lc( $_[1] ); + return lc( $_[1] // "" ); } } -->8---
$ perl5.8.8 -wle'print lc undef' $ perl5.10.0 -wle'print lc undef' $ perl5.12.2 -wle'print lc undef' Use of uninitialized value in lc at -e line 1. $ perl5.14.1 -wle'print lc undef' Use of uninitialized value in lc at -e line 1. $ perl5.16.0 -wle'print lc undef' Use of uninitialized value in lc at -e line 1.
On Mon, Jan 7, 2013 7:44:45 AM, HMBRAND wrote: Show quoted text
> I get loads of these: > > Use of uninitialized value $_[1] in lc at /pro/lib/perl5/ > site_perl/5.16.0/HTML/Element.pm line 838.
What are you doing that is causing undef to be passed to that function? I'm using 5.14.2, and I've never seen that warning. Can you come up with an example that reproduces it? At the least, please insert Carp::cluck("undef") unless defined $_[1]; before the return and show us the call stack.
Subject: Re: [rt.cpan.org #82538] Undefined arguments cause noisy parser in perl 5.16
Date: Tue, 8 Jan 2013 08:43:57 +0100
To: bug-HTML-Tree [...] rt.cpan.org
From: "H.Merijn Brand" <h.m.brand [...] xs4all.nl>
On Mon, 7 Jan 2013 20:38:47 -0500, "Christopher J. Madsen via RT" <bug-HTML-Tree@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=82538 > > > On Mon, Jan 7, 2013 7:44:45 AM, HMBRAND wrote:
> > I get loads of these: > > > > Use of uninitialized value $_[1] in lc at /pro/lib/perl5/ > > site_perl/5.16.0/HTML/Element.pm line 838.
> > What are you doing that is causing undef to be passed to that function? > I'm using 5.14.2, and I've never seen that warning. > > Can you come up with an example that reproduces it? At the least, > please insert > > Carp::cluck("undef") unless defined $_[1]; > > before the return and show us the call stack.
undef at /pro/lib/perl5/site_perl/5.16.0/HTML/Element.pm line 838. HTML::Element::_fold_case_LC('HTML::Element=HASH(0x9327d6c)', undef) called at /pro/lib/perl5/site_perl/5.16.0/HTML/Element.pm line 181 HTML::Element::attr('HTML::Element=HASH(0x9327d6c)', undef) called at /pro/bin/lwp-href line 70 undef at /pro/lib/perl5/site_perl/5.16.0/HTML/Element.pm line 838. HTML::Element::_fold_case_LC('HTML::Element=HASH(0x9442a5c)', undef) called at /pro/lib/perl5/site_perl/5.16.0/HTML/Element.pm line 181 HTML::Element::attr('HTML::Element=HASH(0x9442a5c)', undef) called at /pro/bin/lwp-href line 70 /pro/bin/lwp-href: 68 foreach my $a ($tree->look_down (_tag => qr{^$re_tag$})) { 69 # print STDERR "tag: ", $a->tag, ", ref: ", $a->attr ($tags{$a->tag}), "\n"; 70 my $h = $a->attr ($tags{$a->tag}) or next; 71 $h =~ $pat or next; 72 $opt_f && $h !~ m{\w+://} and substr $h, 0, 0, "$url/"; 73 $ref{$h}++; 74 } -- H.Merijn Brand http://tux.nl Perl Monger http://amsterdam.pm.org/ using perl5.00307 .. 5.17 porting perl5 on HP-UX, AIX, and openSUSE http://mirrors.develooper.com/hpux/ http://www.test-smoke.org/ http://qa.perl.org http://www.goldmark.org/jeff/stupid-disclaimers/
Well, undef is not a valid attribute name, so you shouldn't be calling $a->attr($tags{$a->tag}) if $tags{$a->tag} is undef. I think the warning is appropriate. There are any number of ways to avoid passing undef, e.g. $a->attr($tags{$a->tag} // next)
Subject: Re: [rt.cpan.org #82538] Undefined arguments cause noisy parser in perl 5.16
Date: Tue, 8 Jan 2013 09:35:27 +0100
To: bug-HTML-Tree [...] rt.cpan.org
From: "H.Merijn Brand" <h.m.brand [...] xs4all.nl>
On Tue, 8 Jan 2013 03:11:09 -0500, "Christopher J. Madsen via RT" <bug-HTML-Tree@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=82538 > > > Well, undef is not a valid attribute name, so you shouldn't be calling > $a->attr($tags{$a->tag}) if $tags{$a->tag} is undef. I think the > warning is appropriate. > > There are any number of ways to avoid passing undef, e.g. > > $a->attr($tags{$a->tag} // next)
The error was in not anchoring the alternating pattern, causing it to match more than wanted. Sorry for the noise, my bad vvv v foreach my $a ($tree->look_down (_tag => qr{^(?:$re_tag)$})) { #print STDERR "tag: ", $a->tag, ", ref: ", $a->attr ($tags{$a->tag}), "\n"; my $h = $a->attr ($tags{$a->tag}) or next; $h =~ $pat or next; $opt_f && $h !~ m{\w+://} and substr $h, 0, 0, "$url/"; $ref{$h}++; } -- H.Merijn Brand http://tux.nl Perl Monger http://amsterdam.pm.org/ using perl5.00307 .. 5.17 porting perl5 on HP-UX, AIX, and openSUSE http://mirrors.develooper.com/hpux/ http://www.test-smoke.org/ http://qa.perl.org http://www.goldmark.org/jeff/stupid-disclaimers/