Subject: | warning for empty POST requests |
Since version 6.03, HTTP::Request::Common::POST will emit a warning when
being given an empty $form_ref (which e.g. HTML::Form might do):
$ perl -w -MHTTP::Request::Common -e 'POST "http://unf.ug/", [foo=>"bar"]'
$ perl -w -MHTTP::Request::Common -e 'POST "http://unf.ug/", []'
Use of uninitialized value $content in substitution (s///) at
/usr/local/lib/perl5/site_perl/5.16.0/HTTP/Request/Common.pm line 86.
Please find my suggestion for a fix attached as patch.
Kind regards,
fany
Subject: | HTTP-Message.patch |
diff --git a/lib/HTTP/Request/Common.pm b/lib/HTTP/Request/Common.pm
index 626e048..f6571a5 100644
--- a/lib/HTTP/Request/Common.pm
+++ b/lib/HTTP/Request/Common.pm
@@ -83,7 +83,7 @@ sub POST
$content = $url->query;
# HTML/4.01 says that line breaks are represented as "CR LF" pairs (i.e., `%0D%0A')
- $content =~ s/(?<!%0D)%0A/%0D%0A/g;
+ $content =~ s/(?<!%0D)%0A/%0D%0A/g if defined $content;
}
}
diff --git a/t/common-req.t b/t/common-req.t
index 06d5022..ea6cd09 100644
--- a/t/common-req.t
+++ b/t/common-req.t
@@ -1,7 +1,7 @@
#perl -w
use Test;
-plan tests => 52;
+plan tests => 53;
use HTTP::Request::Common;
@@ -63,6 +63,13 @@ ok($r->header("Subject"), "Heisan");
ok($r->content, "Howdy\n");
ok($r->content_type, "text/plain");
+{
+ my @warnings;
+ local $SIG{__WARN__} = sub { push @warnings, @_ };
+ $r = POST 'http://unf.ug/', [];
+ ok( "@warnings", '', 'empty POST' );
+}
+
#
# POST for File upload
#