Skip to content

Commit

Permalink
Fix exception "gsub called for nil Class" when a multipart form is su…
Browse files Browse the repository at this point in the history
…bmited with a field with a nil name.
  • Loading branch information
Sergio Espeja Almajano committed Jan 8, 2009
1 parent 89bea42 commit 42d9695
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/www/mechanize/form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def request_data
boundary = rand_string(20)
@enctype = "multipart/form-data; boundary=#{boundary}"
params = []
query_params.each { |k,v| params << param_to_multipart(k, v) }
query_params.each { |k,v| params << param_to_multipart(k, v) unless k.nil? }
@file_uploads.each { |f| params << file_to_multipart(f) }
params.collect { |p| "--#{boundary}\r\n#{p}" }.join('') +
"--#{boundary}--\r\n"
Expand Down
15 changes: 14 additions & 1 deletion test/htdocs/form_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,20 @@ <h1>Post Form 3</h1>
</table><br />
<input type="submit" value="Submit" />
</form>
<h1>Get Form 3</h1>

<!-- Post form with multipart/form-data -->
<h1>Post Form 4 - Multipart</h1>
<form name="post_form4_multipart" enctype="multipart/form-data" method="post" action="/form_post">
<table>
<tr>
<td>First Name</td>
<td><input type="text" name="first_name" /></td>
</tr>
</table><br />
<input type="submit" value="Submit" />
</form>

<h1>Get Form 3</h1>
<form name="get_form3" method="get" action="/form_post?great day=yes&one=two">
<table>
<tr>
Expand Down
15 changes: 15 additions & 0 deletions test/test_forms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,21 @@ def test_post
)
end

def test_post_multipart
page = @agent.get("http://localhost/form_test.html")
post_form = page.forms.find { |f| f.name == "post_form4_multipart" }
assert_not_nil(post_form, "Post form is null")
assert_equal("post", post_form.method.downcase)
assert_equal("/form_post", post_form.action)

assert_equal(1, post_form.fields.size)
assert_equal(1, post_form.buttons.size)

page = @agent.submit(post_form, post_form.buttons.first)

assert_not_nil(page)
end

def test_select_box
page = @agent.get("http://localhost/form_test.html")
post_form = page.forms.find { |f| f.name == "post_form1" }
Expand Down

0 comments on commit 42d9695

Please sign in to comment.