From 361bfe6c6d228ab81f42005e70c2e3e51357ae97 Mon Sep 17 00:00:00 2001 From: Lee Jarvis Date: Mon, 11 Feb 2019 17:05:10 +0000 Subject: [PATCH] Ignore fields without names in Form#build_query We shouldn't try to submit empty strings to the server, since browsers also simply ignore these fields Fixes #536 --- lib/mechanize/form.rb | 2 +- test/test_mechanize_form.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/mechanize/form.rb b/lib/mechanize/form.rb index 1509a80a..0c1ba14c 100644 --- a/lib/mechanize/form.rb +++ b/lib/mechanize/form.rb @@ -305,7 +305,7 @@ def build_query(buttons = []) successful_controls = [] (fields + checkboxes).reject do |f| - f.node["disabled"] + f.node["disabled"] || f.node["name"] == "" end.sort.each do |f| case f when Mechanize::Form::CheckBox diff --git a/test/test_mechanize_form.rb b/test/test_mechanize_form.rb index e3b1b751..610a4bdd 100644 --- a/test/test_mechanize_form.rb +++ b/test/test_mechanize_form.rb @@ -65,6 +65,18 @@ def test_build_query_blank_form assert query.all? { |x| x[1] == '' } end + def test_build_query_blank_input_name + html = Nokogiri::HTML <<-HTML +
+ +
+ HTML + + form = Mechanize::Form.new html.at('form'), @mech, @page + + assert_equal [], form.build_query + end + def test_build_query_radio_button_duplicate html = Nokogiri::HTML <<-HTML