Search code examples
perlwww-mechanize

Incorrect filename on WWW::Mechanize submission


As far as I can read from the WWW::Mechanize documentation, you can do the following to submit a file from a string:

$mech->submit_form(
    fields => {
        'UploadedFile' => [[ undef, 'test2.txt', Content => $content ], 1],
    }
);

This should submit a file with name text2.txt, containing the text in $content (in this case, 'The file is a lie.').

The request failed with an internal server error, however, so I examined the request that was sent, and found this:

--xYzZY
Content-Disposition: form-data; name="UploadedFile"; filename="ARRAY(0x9567570)"

The file is a lie.
--xYzZY

That is clearly not the filename I specified, so I wonder: Am I doing something wrong, or is the module bugged?


Solution

  • This is a bug in HTML::Form. I have reported it to the author.

    In the mean time, if you have HTML::Form version 6.00, you can fix things temporarily by commenting out line 1442 in HTML/Form.pm which reads

    $old = $self->file unless defined $old;