From: Andy Grundman Date: Sat, 23 Feb 2008 15:19:50 +0000 (+0000) Subject: HTTP::Body, fixed multipart test to properly clean up temp files X-Git-Tag: v1.00~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FHTTP-Body.git;a=commitdiff_plain;h=1ced50e0624bcb0e1c37780cac004841f5804c52 HTTP::Body, fixed multipart test to properly clean up temp files --- diff --git a/Changes b/Changes index 80d9c5d..083b4be 100644 --- a/Changes +++ b/Changes @@ -4,6 +4,7 @@ This file documents the revision history for Perl extension HTTP::Body. - Added support for chunked requests if no $length value is passed to new(). - Fixed urlencoded parser to handle spaces after semicolons and equal signs in the value. (Tom Heady, http://rt.cpan.org/Ticket/Display.html?id=31055) + - Fixed multipart test to properly clean up temporary files. 0.9 2007-03-27 14:00:00 - Fixed bug where empty fields in multipart/form-data were ignored. diff --git a/lib/HTTP/Body.pm b/lib/HTTP/Body.pm index 3025a88..d178267 100644 --- a/lib/HTTP/Body.pm +++ b/lib/HTTP/Body.pm @@ -60,6 +60,12 @@ Chunked bodies are supported by not passing a length value to new(). It is currently used by L to parse POST bodies. +=head1 NOTES + +When parsing multipart bodies, temporary files are created to store any +uploaded files. You must delete these temporary files yourself after +processing them. + =head1 METHODS =over 4 diff --git a/t/04multipart.t b/t/04multipart.t index 7f2c0f5..1783429 100644 --- a/t/04multipart.t +++ b/t/04multipart.t @@ -27,12 +27,15 @@ for ( my $i = 1; $i <= 12; $i++ ) { $body->add($buffer); } + # Save tempnames for later deletion + my @temps; + for my $field ( keys %{ $body->upload } ) { my $value = $body->upload->{$field}; for ( ( ref($value) eq 'ARRAY' ) ? @{$value} : $value ) { - delete $_->{tempname}; + push @temps, delete $_->{tempname}; } } @@ -41,4 +44,7 @@ for ( my $i = 1; $i <= 12; $i++ ) { is_deeply( $body->upload, $results->{upload}, "$test MultiPart upload" ); cmp_ok( $body->state, 'eq', 'done', "$test MultiPart state" ); cmp_ok( $body->length, '==', $body->content_length, "$test MultiPart length" ); + + # Clean up temp files created + unlink map { $_ } grep { -e $_ } @temps; }