From a1c74af309e7ad13de3d6b318dde48e0e423dcf3 Mon Sep 17 00:00:00 2001 From: SHIMADA Koji Date: Sun, 19 Dec 2010 19:32:56 +0900 Subject: [PATCH] appropriately handle blank values of form --- lib/webrat/core/elements/form.rb | 2 +- spec/integration/mechanize/sample_app.rb | 2 +- spec/integration/mechanize/spec/mechanize_spec.rb | 10 +++++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/webrat/core/elements/form.rb b/lib/webrat/core/elements/form.rb index 5ab345cc..64828d52 100644 --- a/lib/webrat/core/elements/form.rb +++ b/lib/webrat/core/elements/form.rb @@ -110,7 +110,7 @@ def self.query_string_to_params(query_string) 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| Hash[*query.split('=', 2)] } end end diff --git a/spec/integration/mechanize/sample_app.rb b/spec/integration/mechanize/sample_app.rb index af5d8850..3274223e 100644 --- a/spec/integration/mechanize/sample_app.rb +++ b/spec/integration/mechanize/sample_app.rb @@ -30,6 +30,6 @@ class SampleApp < Sinatra::Default end put "/form" do - "Welcome #{params[:email]}" + "Welcome '#{params[:email]}'" end end diff --git a/spec/integration/mechanize/spec/mechanize_spec.rb b/spec/integration/mechanize/spec/mechanize_spec.rb index b2ca743d..70ceee65 100644 --- a/spec/integration/mechanize/spec/mechanize_spec.rb +++ b/spec/integration/mechanize/spec/mechanize_spec.rb @@ -18,7 +18,15 @@ fill_in "Email", :with => "albert@example.com" response = click_button "Add" - response.should contain("Welcome albert@example.com") + response.should contain("Welcome 'albert@example.com'") + end + + it "should submit forms with field whose value is blank" do + visit "http://localhost:9292/form" + fill_in "Email", :with => "" + response = click_button "Add" + + response.should contain("Welcome ''") end it "should not follow external redirects" do