Skip Menu |
 

This queue is for tickets about the WWW-Scripter CPAN distribution.

Report information
The Basics
Id: 84639
Status: resolved
Priority: 0/
Queue: WWW-Scripter

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

Bug Information
Severity: (no value)
Broken in: 0.029
Fixed in: 0.030

Attachments
rt-84639-fix-content-when-not-dom_enabled.patch



Subject: content() assumes document() won't return undef
Download (untitled) / with headers
text/plain 513b
The following code: use WWW::Scripter (); my $w = WWW::Scripter->new; $w->dom_enabled(0); $w->get('http://google.com/'); $w->content; throws this error: Can't call method "charset" on an undefined value at .../WWW/Scripter.pm line 151. This appears to be because WWW::Scripter explicitly undefines the "document" attribute in its "_update_page" method, but the "content" method doesn't check for its existence before doing its own processing. This might be the cause of the behaviour described in RT #84472.
Download (untitled) / with headers
text/plain 113b
On Mon Apr 15 11:01:15 2013, LXP wrote: Show quoted text
> This might be the cause of the behaviour described in RT #84472.
Nope.
Download (untitled) / with headers
text/plain 587b
On Mon Apr 15 11:01:15 2013, LXP wrote: Show quoted text
> The following code: > > use WWW::Scripter (); > > my $w = WWW::Scripter->new; > $w->dom_enabled(0); > $w->get('http://google.com/'); > $w->content; > > throws this error: > > Can't call method "charset" on an undefined value at > .../WWW/Scripter.pm line 151. > > This appears to be because WWW::Scripter explicitly undefines the > "document" attribute in its "_update_page" method, but the "content" > method doesn't check for its existence before doing its own > processing.
The attached patch includes a test and a fix for this problem.
Subject: rt-84639-fix-content-when-not-dom_enabled.patch
diff --git a/lib/WWW/Scripter.pm b/lib/WWW/Scripter.pm index 71f335f..6f05f8b 100644 --- a/lib/WWW/Scripter.pm +++ b/lib/WWW/Scripter.pm @@ -146,7 +146,7 @@ sub title { (shift->document||return)->title(@_) } sub content { my $self = shift; - if($self->is_html) { + if($self->is_html && $self->document) { my %parms = @_; my $cs = (my $doc = $self->document)->charset;; if(exists $parms{format} && $parms{format} eq 'text') { diff --git a/t/dom.t b/t/dom.t index 2e297ac..483c291 100644 --- a/t/dom.t +++ b/t/dom.t @@ -182,14 +182,15 @@ END 'window event handlers are not called when scripts are off'; } -use tests 2; # dom_enabled +use tests 3; # dom_enabled { my $m = new WWW::Scripter; ok $m->dom_enabled(0), 'DOM enabled by default'; - $m->get('data:text/html,'); + $m->get('data:text/html,123'); ok !$m->document, 'dom_enabled' or diag $m->document->URL; + is $m->content, '123', 'content works when !dom_enabled'; } use tests 1; # DOM tree ->charset
Download (untitled) / with headers
text/plain 272b
On Thu May 02 13:12:52 2013, LXP wrote: Show quoted text
> (I've explicitly added your unmunged email address to this ticket now, > because looking at your default RT email address I suspect that RT has > just been shooting all of the past correspondence into the aether.)
Ditto this one!
This patch is available via version 0.030 of WWW-Scripter, released earlier today.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.