
Webrat does not pass empty form fields correctly to mechanize
Reported by Mark O'Shea | July 2nd, 2010 @ 10:14 AM
When a form field is left empty on submit, Webrat passes
{"name" => "name"} to mechanize, rather than {"name" => ""}
so its not possible to submit empty fields in a form.
I've added a failing test, as well as the patch and made a pull request
----------------------- lib/webrat/core/elements/form.rb -----------------------
index 5ab345c..1a1cd88 100644
@@ -110,7 +110,10 @@ module Webrat
when :rack, :sinatra
Rack::Utils.parse_nested_query(query_string)
else
- query_string.split('&').map {|query| { query.split('=').first => query.split('=').last }}
+ query_string.split('&').map {|query|
+ query.match /^(.*?)=(.*)$/
+ { $1 => $2 }
+ }
end
end
------------------------ spec/private/core/form_spec.rb ------------------------
index aa28fa1..5d17556 100644
@@ -49,3 +49,24 @@ describe "Multiple nested params" do
click_button
end
end
+
+describe "Empty fields in form should be submitted as empty" do
+ it "should post empty fields" do
+ Webrat.configuration.mode = :mechanize
+
+ with_html <<-HTML
+ <html>
+ <form method="post" action="/fields">
+ <input type="text" value="" name="user" />
+ <input type="submit" />
+ </form>
+ </html>
+ HTML
+
+ params = [{"user"=>""}]
+
+ webrat_session.should_receive(:post).with("/fields", params)
+ click_button
+ end
+
+end
Comments and changes to this ticket
-
Ash Berlin August 27th, 2010 @ 09:28 AM
A perhaps simpler fix than using a regexp match is
.map { |query| Hash[ *query.split( '=', 2) ] }
-
Ash Berlin October 28th, 2010 @ 05:23 AM
I don't think so, no - all browsers I tested in (IE, Safari and FF) send text=&text2= for empty text values.
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.
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.