[Catalyst-commits] r13330 - in trunk/HTTP-Body: lib/HTTP/Body t t/data/multipart

autarch at dev.catalyst.perl.org autarch at dev.catalyst.perl.org
Sun Jun 6 03:50:05 GMT 2010


Author: autarch
Date: 2010-06-06 04:50:05 +0100 (Sun, 06 Jun 2010)
New Revision: 13330

Modified:
   trunk/HTTP-Body/lib/HTTP/Body/MultiPart.pm
   trunk/HTTP-Body/t/08multipart-suffix.t
   trunk/HTTP-Body/t/data/multipart/014-content.dat
   trunk/HTTP-Body/t/data/multipart/014-headers.pml
Log:
Make sure we do not include a directory separator in the temp file suffix.

Note that this will not get the right answer if the extension actually has a
path separator character in it for some insane reason.

Modified: trunk/HTTP-Body/lib/HTTP/Body/MultiPart.pm
===================================================================
--- trunk/HTTP-Body/lib/HTTP/Body/MultiPart.pm	2010-06-05 21:55:30 UTC (rev 13329)
+++ trunk/HTTP-Body/lib/HTTP/Body/MultiPart.pm	2010-06-06 03:50:05 UTC (rev 13330)
@@ -270,7 +270,7 @@
             $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 );
 

Modified: trunk/HTTP-Body/t/08multipart-suffix.t
===================================================================
--- trunk/HTTP-Body/t/08multipart-suffix.t	2010-06-05 21:55:30 UTC (rev 13329)
+++ trunk/HTTP-Body/t/08multipart-suffix.t	2010-06-06 03:50:05 UTC (rev 13330)
@@ -6,7 +6,7 @@
 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 @@
         $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 {

Modified: trunk/HTTP-Body/t/data/multipart/014-content.dat
===================================================================
--- trunk/HTTP-Body/t/data/multipart/014-content.dat	2010-06-05 21:55:30 UTC (rev 13329)
+++ trunk/HTTP-Body/t/data/multipart/014-content.dat	2010-06-06 03:50:05 UTC (rev 13330)
@@ -4,4 +4,10 @@
 
 Some random junk
 
+------------0xKhTmLbOuNdArY
+Content-Disposition: form-data; name="upload2"; filename="C:\Documents\foo.bar\baz.txt"
+Content-Type: text/plain
+
+blah blah
+
 ------------0xKhTmLbOuNdArY--

Modified: trunk/HTTP-Body/t/data/multipart/014-headers.pml
===================================================================
--- trunk/HTTP-Body/t/data/multipart/014-headers.pml	2010-06-05 21:55:30 UTC (rev 13329)
+++ trunk/HTTP-Body/t/data/multipart/014-headers.pml	2010-06-06 03:50:05 UTC (rev 13330)
@@ -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"
 }




More information about the Catalyst-commits mailing list