Skip to content

Commit

Permalink
Ignore fields without names in Form#build_query
Browse files Browse the repository at this point in the history
We shouldn't try to submit empty strings to the server, since browsers
also simply ignore these fields

Fixes #536
  • Loading branch information
leejarvis committed Feb 12, 2019
1 parent d4880d3 commit 361bfe6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/mechanize/form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions test/test_mechanize_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
<form>
<input type="text" name="" value="foo" />
</form>
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
<form>
Expand Down

0 comments on commit 361bfe6

Please sign in to comment.