#390 new
Jarl Friis

Webrat does not pass empty form file fields correctly to Rails

Reported by Jarl Friis | August 9th, 2010 @ 09:44 AM

When a page contains a file field and no file is uploaded, then a parameter is generated anyway. This was also the problem with rack testing some time ago (see http://rack.lighthouseapp.com/projects/22435/tickets/37).

Here is a minimal patch that solves the problem for webrat (tests should of course be made

--- /var/lib/gems/1.8/gems/webrat-0.7.1/lib/webrat/core/elements/form.rb.org    2010-05-26 21:11:16.978887686 +0200
+++ /var/lib/gems/1.8/gems/webrat-0.7.1/lib/webrat/core/elements/form.rb        2010-05-26 21:39:40.728106794 +0200
@@ -47,6 +47,7 @@

       fields.each do |field|
         next if field.to_query_string.nil?
+        next if field.is_a?(FileField) && field.test_uploaded_file.blank?
         replaces.merge!({field.digest_value => field.test_uploaded_file}) if field.is_a?(FileField)
         query_string << field.to_query_string
       end

Jarl

Comments and changes to this ticket

  • Ryan Kinderman

    Ryan Kinderman August 30th, 2010 @ 12:29 PM

    What's the status on this? Need a test?

  • Ryan Kinderman

    Ryan Kinderman September 11th, 2010 @ 10:58 AM

    In retrospect, this is something that should really be handled by the system receiving the request. I see nothing in RFC1867 or RFC2388 that recommends that user agents exclude file parameters when there is no file specified. This issue should be closed.

  • Jarl Friis

    Jarl Friis September 13th, 2010 @ 03:24 AM

    Quote from "http://www.w3.org/TR/html4/interact/forms.html#h-17.13.2"
    If a control doesn't have a current value when the form is submitted, user agents are not required to treat it as a successful control.

    In practise there are no browser that treat a file control as "succesful control" when the current value is empty, which means that if a file field is not filled, then the file control is excluded from the submitted form data set.

    @Ryan: You are right when you say "this is something that should really be handled by the system receiving the request". Webapps should work with the current behaviour of webrat, because the spec states "user agents are not required ...". Webrat is aparantly (at this moment) one client that does treat file controls without current value as "successful control" So webrat does not violate the spec, so web-apps should be able to handle current behaviour of webrat

    However if webrat is supposed to mimic the behaviour of common browser, then the behaviour of webrat should change according to the patch supplied with this issue.

    Jarl

  • Ryan Kinderman

    Ryan Kinderman December 7th, 2010 @ 08:46 PM

    We're migrating to Capybara at work, so I shifted my focus there for fixing this issue which, strangely, also exists in Capybara. Since the issue is the same in both cases, here's my pull request for Capybara, which might help here as well:

    https://github.com/jnicklas/capybara/pull/224

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Ruby Acceptance Testing for Web applications.

Shared Ticket Bins

People watching this ticket

Referenced by

Pages