Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"0" value bug in Mojo::UserAgent::Transactor #641

Closed
s-murata opened this issue Jul 2, 2014 · 2 comments
Closed

"0" value bug in Mojo::UserAgent::Transactor #641

s-murata opened this issue Jul 2, 2014 · 2 comments

Comments

@s-murata
Copy link

s-murata commented Jul 2, 2014

When upload a file named 0, uploaded a file named file.
This cause is in a _multipart method at Mojo::UserAgent::Transactor.
In this method, used || operators and not properly handled a 0 value.

          $value->{filename} ||= basename $file->path
            if $file->isa('Mojo::Asset::File');

and

        $filename = delete $value->{filename} || $name;
@s-murata
Copy link
Author

s-murata commented Jul 2, 2014

I wrote a patch below.

--- Transactor.pm       2014-06-12 04:01:12.000000000 +0900
+++ /tmp/Transactor.pm  2014-07-02 18:06:30.975458888 +0900
@@ -208,7 +208,7 @@
         if (my $file = delete $value->{file}) {
           $file = Mojo::Asset::File->new(path => $file) unless ref $file;
           $part->asset($file);
-          $value->{filename} ||= basename $file->path
+          $value->{filename} //= basename $file->path
             if $file->isa('Mojo::Asset::File');
         }

@@ -218,7 +218,7 @@
         }

         # Filename and headers
-        $filename = delete $value->{filename} || $name;
+        $filename = delete $value->{filename} // $name;
         $filename = encode $charset, $filename if $charset;
         $headers->from_hash($value);
       }
@@ -232,7 +232,7 @@
       # Content-Disposition
       $name = encode $charset, $name if $charset;
       my $disposition = qq{form-data; name="$name"};
-      $disposition .= qq{; filename="$filename"} if $filename;
+      $disposition .= qq{; filename="$filename"} if defined $filename;
       $headers->content_disposition($disposition);
     }
   }

@kraih kraih closed this as completed in dbe303b Jul 2, 2014
@kraih
Copy link
Member

kraih commented Jul 2, 2014

Thanks, fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants