From bfaf7ec251265f6270d534ecaab66340b03e8f74 Mon Sep 17 00:00:00 2001 From: Mikko Johannes Koivunalho Date: Sun, 5 Oct 2025 15:06:44 +0200 Subject: [PATCH 1/4] Fix content(raw=>1) dies when there is no response * https://github.com/libwww-perl/WWW-Mechanize/issues/384 --- lib/WWW/Mechanize.pm | 3 ++- t/content.t | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/WWW/Mechanize.pm b/lib/WWW/Mechanize.pm index dd5064aa..75e0a4d4 100644 --- a/lib/WWW/Mechanize.pm +++ b/lib/WWW/Mechanize.pm @@ -899,7 +899,8 @@ sub content { my $content = $self->{content}; if ( delete $params{raw} ) { - $content = $self->response()->content(); + my $res = $self->response(); + $content = $res->content() if $res; } elsif ( delete $params{decoded_by_headers} ) { $content = $self->response()->decoded_content( charset => 'none' ); diff --git a/t/content.t b/t/content.t index c146b715..91029de3 100644 --- a/t/content.t +++ b/t/content.t @@ -37,6 +37,7 @@ my $mech = WWW::Mechanize->new(); $mech->{base} = 'http://example.com/'; is( $mech->content, undef, 'content starts out as undef' ); +is( $mech->content(raw=>1), undef, 'raw content is just as undef as normal' ); $mech->update_html($html); From 856cd932e956e985d2e87b04b663c99f24330a5f Mon Sep 17 00:00:00 2001 From: Mikko Johannes Koivunalho Date: Fri, 10 Oct 2025 01:53:09 +0200 Subject: [PATCH 2/4] Tidify t/content.t --- t/content.t | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/t/content.t b/t/content.t index 91029de3..5c8e95a9 100644 --- a/t/content.t +++ b/t/content.t @@ -37,7 +37,8 @@ my $mech = WWW::Mechanize->new(); $mech->{base} = 'http://example.com/'; is( $mech->content, undef, 'content starts out as undef' ); -is( $mech->content(raw=>1), undef, 'raw content is just as undef as normal' ); +is( $mech->content( raw => 1 ), + undef, 'raw content is just as undef as normal' ); $mech->update_html($html); @@ -66,10 +67,8 @@ my $content = $mech->content( base_href => 'foo' ); like( $content, qr/base href="foo"/, 'Found the base href' ); $content = $mech->content( base_href => undef ); -like( - $content, qr[base href="http://example.com/"], - 'Found the new base href' -); +like( $content, qr[base href="http://example.com/"], + 'Found the new base href' ); $mech->{res} = Test::MockResponse->new( raw_content => 'this is the raw content', @@ -81,10 +80,7 @@ $content = $mech->content( raw => 1 ); is( $content, 'this is the raw content', 'raw => 1' ); $content = $mech->content( decoded_by_headers => 1 ); -is( - $content, 'this is a slightly decoded content', - 'decoded_by_headers => 1' -); +is( $content, 'this is a slightly decoded content', 'decoded_by_headers => 1' ); $content = $mech->content( charset => 'whatever' ); is( $content, 'this is charset whatever', 'charset => ...' ); From cc936a0326123cd1c476909b8fb8a383084d8871 Mon Sep 17 00:00:00 2001 From: Mikko Johannes Koivunalho Date: Fri, 10 Oct 2025 23:40:56 +0200 Subject: [PATCH 3/4] Tidify t/content.t again --- t/content.t | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/t/content.t b/t/content.t index 5c8e95a9..86030dbd 100644 --- a/t/content.t +++ b/t/content.t @@ -37,8 +37,10 @@ my $mech = WWW::Mechanize->new(); $mech->{base} = 'http://example.com/'; is( $mech->content, undef, 'content starts out as undef' ); -is( $mech->content( raw => 1 ), - undef, 'raw content is just as undef as normal' ); +is( + $mech->content( raw => 1 ), + undef, 'raw content is just as undef as normal' +); $mech->update_html($html); @@ -67,8 +69,10 @@ my $content = $mech->content( base_href => 'foo' ); like( $content, qr/base href="foo"/, 'Found the base href' ); $content = $mech->content( base_href => undef ); -like( $content, qr[base href="http://example.com/"], - 'Found the new base href' ); +like( + $content, qr[base href="http://example.com/"], + 'Found the new base href' +); $mech->{res} = Test::MockResponse->new( raw_content => 'this is the raw content', @@ -80,7 +84,10 @@ $content = $mech->content( raw => 1 ); is( $content, 'this is the raw content', 'raw => 1' ); $content = $mech->content( decoded_by_headers => 1 ); -is( $content, 'this is a slightly decoded content', 'decoded_by_headers => 1' ); +is( + $content, 'this is a slightly decoded content', + 'decoded_by_headers => 1' +); $content = $mech->content( charset => 'whatever' ); is( $content, 'this is charset whatever', 'charset => ...' ); From d09c251762b318434aa066ab198e6c4ad27cef04 Mon Sep 17 00:00:00 2001 From: Mikko Johannes Koivunalho Date: Fri, 10 Oct 2025 23:41:11 +0200 Subject: [PATCH 4/4] Tidify lib/WWW/Mechanize.pm --- lib/WWW/Mechanize.pm | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/WWW/Mechanize.pm b/lib/WWW/Mechanize.pm index 75e0a4d4..bf48042b 100644 --- a/lib/WWW/Mechanize.pm +++ b/lib/WWW/Mechanize.pm @@ -1715,10 +1715,9 @@ sub form_action { my ( $self, $action ) = @_; my $temp; - my @matches = grep { - defined( $temp = $_->action ) - and ( $temp =~ m/$action/msx ) - } $self->forms; + my @matches + = grep { defined( $temp = $_->action ) and ( $temp =~ m/$action/msx ) } + $self->forms; my $nmatches = @matches; if ( $nmatches > 0 ) {