Make sure we do not include a directory separator in the temp file suffix.
Dave Rolsky [Sun, 6 Jun 2010 03:50:05 +0000 (03:50 +0000)]
Note that this will not get the right answer if the extension actually has a
path separator character in it for some insane reason.

lib/HTTP/Body/MultiPart.pm
t/08multipart-suffix.t
t/data/multipart/014-content.dat
t/data/multipart/014-headers.pml

index 16f008e..5b0adff 100644 (file)
@@ -270,7 +270,7 @@ sub handler {
             $part->{filename} = $filename;
 
             if ( $filename ne "" ) {
-                my $suffix = $filename =~ /[^.]+(\..+)$/ ? $1 : q{};
+                my $suffix = $filename =~ /[^.]+(\.[^\\\/]+)$/ ? $1 : q{};
 
                 my $fh = File::Temp->new( UNLINK => 0, DIR => $self->tmpdir, SUFFIX => $suffix );
 
index 7374223..367db05 100644 (file)
@@ -6,7 +6,7 @@ use warnings;
 use FindBin;
 use lib "$FindBin::Bin/lib";
 
-use Test::More tests => 4;
+use Test::More tests => 6;
 use Test::Deep;
 
 use Cwd;
@@ -48,6 +48,16 @@ my $path = catdir( getcwd(), 't', 'data', 'multipart' );
         $uploads->{upload}{tempname}, qr/\.foo\.txt$/,
         'tempname preserves .foo.txt suffix'
     );
+
+    like(
+        $uploads->{upload2}{tempname}, qr/\.txt$/,
+        'tempname preserves .txt suffix when dir name has .'
+    );
+
+    unlike(
+        $uploads->{upload2}{tempname}, qr/\\/,
+        'tempname only gets extension from filename, not from a directory name'
+    );
 }
 
 sub uploads_for {
index 8db2516..c766773 100644 (file)
@@ -4,4 +4,10 @@ Content-Type: text/plain
 \r
 Some random junk\r
 \r
+------------0xKhTmLbOuNdArY\r
+Content-Disposition: form-data; name="upload2"; filename="C:\Documents\foo.bar\baz.txt"\r
+Content-Type: text/plain\r
+\r
+blah blah\r
+\r
 ------------0xKhTmLbOuNdArY--\r
index 177c64a..d23f01b 100644 (file)
@@ -1,5 +1,5 @@
 {
   "User-Agent" => "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/312.1 (KHTML, like Gecko) Safari/312",
-  "Content-Length" => 181,
+  "Content-Length" => 339,
   "Content-Type" => "multipart/form-data; boundary=----------0xKhTmLbOuNdArY"
 }