mechanize 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of mechanize might be problematic. Click here for more details.

@@ -1,6 +1,19 @@
1
1
  = Mechanize CHANGELOG
2
2
 
3
- === HEAD
3
+ === 0.9.2 / 2009/03/05
4
+
5
+ * New Features:
6
+ * Mechanize#submit and Form#submit take arbitrary headers(thanks penguincoder)
7
+
8
+ * Bug Fixes:
9
+ * Fixed a bug with bad cookie parsing
10
+ * Form::RadioButton#click unchecks other buttons (RF #24159)
11
+ * Fixed problems with Iconv (RF #24190, RF #24192, RF #24043)
12
+ * POST parameters should be CGI escaped
13
+ * Made Content-Type match case insensitive (Thanks Kelly Reynolds)
14
+ * Non-string form parameters work
15
+
16
+ === 0.9.1 2009/02/23
4
17
 
5
18
  * New Features:
6
19
  * Encoding may be specified for a page: Page#encoding=
File without changes
File without changes
File without changes
File without changes
@@ -1,10 +1,10 @@
1
- EXAMPLES.txt
2
- FAQ.txt
3
- GUIDE.txt
4
- History.txt
5
- LICENSE.txt
1
+ CHANGELOG.rdoc
2
+ EXAMPLES.rdoc
3
+ FAQ.rdoc
4
+ GUIDE.rdoc
5
+ LICENSE.rdoc
6
6
  Manifest.txt
7
- README.txt
7
+ README.rdoc
8
8
  Rakefile
9
9
  examples/flickr_upload.rb
10
10
  examples/mech-dump.rb
@@ -13,20 +13,29 @@ a history.
13
13
 
14
14
  == Dependencies
15
15
 
16
- * ruby 1.8.4
17
- * hpricot[http://code.whytheluckystiff.net/hpricot/]
16
+ * ruby 1.8.6
17
+ * nokogiri[http://nokogiri.rubyforge.org]
18
18
 
19
+ == SUPPORT:
20
+
21
+ The mechanize mailing list is available here:
22
+
23
+ * http://rubyforge.org/mailman/listinfo/mechanize-users
24
+
25
+ The bug tracker is available here:
26
+
27
+ * http://rubyforge.org/tracker/?atid=5709&group_id=1453
19
28
 
20
29
  == Examples
21
30
 
22
- If you are just starting, check out the GUIDE[link://files/GUIDE_txt.html].
23
- Also, check out the EXAMPLES[link://files/EXAMPLES_txt.html] file.
31
+ If you are just starting, check out the GUIDE[link://files/GUIDE_rdoc.html].
32
+ Also, check out the EXAMPLES[link://files/EXAMPLES_rdoc.html] file.
24
33
 
25
34
  == Authors
26
35
 
27
36
  Copyright (c) 2005 by Michael Neumann (mneumann@ntecs.de)
28
37
 
29
- Copyright (c) 2006-2008:
38
+ Copyright (c) 2006-2009:
30
39
 
31
40
  * {Aaron Patterson}[http://tenderlovemaking.com] (aaronp@rubyforge.org)
32
41
  * {Mike Dalessio}[http://mike.daless.io] (mike@csa.net)
@@ -47,5 +56,5 @@ library!
47
56
 
48
57
  == License
49
58
 
50
- This library is distributed under the GPL. Please see the LICENSE[link://files/LICENSE_txt.html] file.
59
+ This library is distributed under the GPL. Please see the LICENSE[link://files/LICENSE_rdoc.html] file.
51
60
 
data/Rakefile CHANGED
@@ -8,6 +8,9 @@ HOE = Hoe.new('mechanize', WWW::Mechanize::VERSION) do |p|
8
8
  p.rubyforge_name = 'mechanize'
9
9
  p.developer('Aaron Patterson','aaronp@rubyforge.org')
10
10
  p.developer('Mike Dalessio','mike.dalessio@gmail.com')
11
+ p.readme_file = 'README.rdoc'
12
+ p.history_file = 'CHANGELOG.rdoc'
13
+ p.extra_rdoc_files = FileList['*.rdoc']
11
14
  p.summary = "Mechanize provides automated web-browsing"
12
15
  p.extra_deps = [['nokogiri', '>= 1.2.1']]
13
16
  end
@@ -48,7 +48,7 @@ module WWW
48
48
  class Mechanize
49
49
  ##
50
50
  # The version of Mechanize you are using.
51
- VERSION = '0.9.1'
51
+ VERSION = '0.9.2'
52
52
 
53
53
  ##
54
54
  # User Agent aliases
@@ -328,14 +328,15 @@ module WWW
328
328
  # agent.submit(page.forms.first)
329
329
  # With a button
330
330
  # agent.submit(page.forms.first, page.forms.first.buttons.first)
331
- def submit(form, button=nil)
331
+ def submit(form, button=nil, headers={})
332
332
  form.add_button_to_query(button) if button
333
333
  case form.method.upcase
334
334
  when 'POST'
335
- post_form(form.action, form)
335
+ post_form(form.action, form, headers)
336
336
  when 'GET'
337
337
  get( :url => form.action.gsub(/\?[^\?]*$/, ''),
338
338
  :params => form.build_query,
339
+ :headers => headers,
339
340
  :referer => form.page
340
341
  )
341
342
  else
@@ -384,7 +385,7 @@ module WWW
384
385
  hash[:uri].to_s
385
386
  end
386
387
 
387
- def post_form(url, form)
388
+ def post_form(url, form, headers = {})
388
389
  cur_page = form.page || current_page ||
389
390
  Page.new( nil, {'content-type'=>'text/html'})
390
391
 
@@ -400,7 +401,7 @@ module WWW
400
401
  :headers => {
401
402
  'Content-Type' => form.enctype,
402
403
  'Content-Length' => request_data.size.to_s,
403
- })
404
+ }.merge(headers))
404
405
  add_to_history(page)
405
406
  page
406
407
  end
@@ -26,8 +26,9 @@ module WWW
26
26
  cache_obj[:keep_alive_options][k.intern] = v
27
27
  end
28
28
  end
29
- body = Util.to_native_charset(page.body)
30
- if page.is_a?(Page) && body =~ /Set-Cookie/
29
+
30
+
31
+ if page.is_a?(Page) && page.body =~ /Set-Cookie/n
31
32
  page.search('//meta[@http-equiv="Set-Cookie"]').each do |meta|
32
33
  Cookie::parse(uri, meta['content']) { |c|
33
34
  Mechanize.log.debug("saved cookie: #{c}") if Mechanize.log
@@ -12,11 +12,13 @@ module WWW
12
12
  first_elem.strip!
13
13
  key, value = first_elem.split(/=/, 2)
14
14
 
15
+ cookie = nil
15
16
  begin
16
17
  cookie = new(key, WEBrick::HTTPUtils.dequote(value))
17
18
  rescue
18
19
  log.warn("Couldn't parse key/value: #{first_elem}") if log
19
20
  end
21
+ next unless cookie
20
22
 
21
23
  cookie_elem.each{|pair|
22
24
  pair.strip!
@@ -126,8 +126,8 @@ module WWW
126
126
  end
127
127
 
128
128
  # Submit this form with the button passed in
129
- def submit(button=nil)
130
- @mech.submit(self, button)
129
+ def submit button=nil, headers = {}
130
+ @mech.submit(self, button, headers)
131
131
  end
132
132
 
133
133
  # Submit form using +button+. Defaults
@@ -140,7 +140,7 @@ module WWW
140
140
  # It converts charset of query value of fields into excepted one.
141
141
  def proc_query(field)
142
142
  field.query_value.map{|(name, val)|
143
- [from_native_charset(name), from_native_charset(val)]
143
+ [from_native_charset(name), from_native_charset(val.to_s)]
144
144
  }
145
145
  end
146
146
  private :proc_query
@@ -22,7 +22,7 @@ module WWW
22
22
  end
23
23
 
24
24
  def click
25
- @checked = !@checked
25
+ checked ? uncheck : check
26
26
  end
27
27
 
28
28
  private
@@ -24,13 +24,19 @@ module WWW
24
24
  attr_accessor :encoding
25
25
 
26
26
  def initialize(uri=nil, response=nil, body=nil, code=nil, mech=nil)
27
+ @encoding = nil
28
+ response.each do |header,v|
29
+ next unless v =~ /charset/i
30
+ @encoding = v.split('=').last.strip
31
+ end
32
+ @encoding ||= Util.detect_charset(body)
33
+ body = Util.to_native_charset(body, @encoding) rescue body
34
+
27
35
  super(uri, response, body, code)
28
- @encoding = Util.detect_charset(body)
29
36
  @mech ||= mech
30
37
 
31
38
  raise Mechanize::ContentTypeError.new(response['content-type']) unless
32
- response['content-type'] =~ /^(text\/html)|(application\/xhtml\+xml)/
33
-
39
+ response['content-type'] =~ /^(text\/html)|(application\/xhtml\+xml)/i
34
40
  @parser = @links = @forms = @meta = @bases = @frames = @iframes = nil
35
41
  end
36
42
 
@@ -1,3 +1,5 @@
1
+ require 'cgi'
2
+
1
3
  module WWW
2
4
  class Mechanize
3
5
  class Util
@@ -12,7 +14,7 @@ module WWW
12
14
  parameters.map { |k,v|
13
15
  if k
14
16
  # WEBrick::HTTP.escape* has some problems about m17n on ruby-1.9.*.
15
- [URI.escape(k.to_s), URI.escape(v.to_s)].join("=")
17
+ [CGI.escape(k.to_s), CGI.escape(v.to_s)].join("=")
16
18
  =begin
17
19
  [WEBrick::HTTPUtils.escape_form(k.to_s),
18
20
  WEBrick::HTTPUtils.escape_form(v.to_s)].join("=")
@@ -2,37 +2,37 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{mechanize}
5
- s.version = "0.8.5.20081221192100"
5
+ s.version = "0.9.1.20090304135355"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Aaron Patterson", "Mike Dalessio"]
9
- s.date = %q{2008-12-21}
9
+ s.date = %q{2009-03-04}
10
10
  s.description = %q{The Mechanize library is used for automating interaction with websites. Mechanize automatically stores and sends cookies, follows redirects, can follow links, and submit forms. Form fields can be populated and submitted. Mechanize also keeps track of the sites that you have visited as a history.}
11
11
  s.email = ["aaronp@rubyforge.org", "mike.dalessio@gmail.com"]
12
- s.extra_rdoc_files = ["EXAMPLES.txt", "FAQ.txt", "GUIDE.txt", "History.txt", "LICENSE.txt", "Manifest.txt", "README.txt"]
13
- s.files = ["EXAMPLES.txt", "FAQ.txt", "GUIDE.txt", "History.txt", "LICENSE.txt", "Manifest.txt", "README.txt", "Rakefile", "examples/flickr_upload.rb", "examples/mech-dump.rb", "examples/proxy_req.rb", "examples/rubyforge.rb", "examples/spider.rb", "lib/mechanize.rb", "lib/www/mechanize.rb", "lib/www/mechanize/chain.rb", "lib/www/mechanize/chain/auth_headers.rb", "lib/www/mechanize/chain/body_decoding_handler.rb", "lib/www/mechanize/chain/connection_resolver.rb", "lib/www/mechanize/chain/custom_headers.rb", "lib/www/mechanize/chain/handler.rb", "lib/www/mechanize/chain/header_resolver.rb", "lib/www/mechanize/chain/parameter_resolver.rb", "lib/www/mechanize/chain/post_connect_hook.rb", "lib/www/mechanize/chain/pre_connect_hook.rb", "lib/www/mechanize/chain/request_resolver.rb", "lib/www/mechanize/chain/response_body_parser.rb", "lib/www/mechanize/chain/response_header_handler.rb", "lib/www/mechanize/chain/response_reader.rb", "lib/www/mechanize/chain/ssl_resolver.rb", "lib/www/mechanize/chain/uri_resolver.rb", "lib/www/mechanize/content_type_error.rb", "lib/www/mechanize/cookie.rb", "lib/www/mechanize/cookie_jar.rb", "lib/www/mechanize/file.rb", "lib/www/mechanize/file_response.rb", "lib/www/mechanize/file_saver.rb", "lib/www/mechanize/form.rb", "lib/www/mechanize/form/button.rb", "lib/www/mechanize/form/check_box.rb", "lib/www/mechanize/form/field.rb", "lib/www/mechanize/form/file_upload.rb", "lib/www/mechanize/form/image_button.rb", "lib/www/mechanize/form/multi_select_list.rb", "lib/www/mechanize/form/option.rb", "lib/www/mechanize/form/radio_button.rb", "lib/www/mechanize/form/select_list.rb", "lib/www/mechanize/headers.rb", "lib/www/mechanize/history.rb", "lib/www/mechanize/inspect.rb", "lib/www/mechanize/list.rb", "lib/www/mechanize/monkey_patch.rb", "lib/www/mechanize/page.rb", "lib/www/mechanize/page/base.rb", "lib/www/mechanize/page/frame.rb", "lib/www/mechanize/page/link.rb", "lib/www/mechanize/page/meta.rb", "lib/www/mechanize/pluggable_parsers.rb", "lib/www/mechanize/redirect_limit_reached_error.rb", "lib/www/mechanize/redirect_not_get_or_head_error.rb", "lib/www/mechanize/response_code_error.rb", "lib/www/mechanize/unsupported_scheme_error.rb", "lib/www/mechanize/util.rb", "mechanize.gemspec", "test/chain/test_argument_validator.rb", "test/chain/test_custom_headers.rb", "test/chain/test_parameter_resolver.rb", "test/chain/test_request_resolver.rb", "test/chain/test_response_reader.rb", "test/data/htpasswd", "test/data/server.crt", "test/data/server.csr", "test/data/server.key", "test/data/server.pem", "test/helper.rb", "test/htdocs/alt_text.html", "test/htdocs/bad_form_test.html", "test/htdocs/button.jpg", "test/htdocs/empty_form.html", "test/htdocs/file_upload.html", "test/htdocs/find_link.html", "test/htdocs/form_multi_select.html", "test/htdocs/form_multival.html", "test/htdocs/form_no_action.html", "test/htdocs/form_no_input_name.html", "test/htdocs/form_select.html", "test/htdocs/form_select_all.html", "test/htdocs/form_select_none.html", "test/htdocs/form_select_noopts.html", "test/htdocs/form_set_fields.html", "test/htdocs/form_test.html", "test/htdocs/frame_test.html", "test/htdocs/google.html", "test/htdocs/iframe_test.html", "test/htdocs/index.html", "test/htdocs/link with space.html", "test/htdocs/meta_cookie.html", "test/htdocs/no_title_test.html", "test/htdocs/relative/tc_relative_links.html", "test/htdocs/tc_bad_links.html", "test/htdocs/tc_base_link.html", "test/htdocs/tc_blank_form.html", "test/htdocs/tc_checkboxes.html", "test/htdocs/tc_encoded_links.html", "test/htdocs/tc_follow_meta.html", "test/htdocs/tc_form_action.html", "test/htdocs/tc_links.html", "test/htdocs/tc_no_attributes.html", "test/htdocs/tc_pretty_print.html", "test/htdocs/tc_radiobuttons.html", "test/htdocs/tc_referer.html", "test/htdocs/tc_relative_links.html", "test/htdocs/tc_textarea.html", "test/htdocs/unusual______.html", "test/servlets.rb", "test/ssl_server.rb", "test/test_authenticate.rb", "test/test_bad_links.rb", "test/test_blank_form.rb", "test/test_checkboxes.rb", "test/test_content_type.rb", "test/test_cookie_class.rb", "test/test_cookie_jar.rb", "test/test_cookies.rb", "test/test_encoded_links.rb", "test/test_errors.rb", "test/test_follow_meta.rb", "test/test_form_action.rb", "test/test_form_as_hash.rb", "test/test_form_button.rb", "test/test_form_no_inputname.rb", "test/test_forms.rb", "test/test_frames.rb", "test/test_get_headers.rb", "test/test_gzipping.rb", "test/test_hash_api.rb", "test/test_history.rb", "test/test_history_added.rb", "test/test_html_unscape_forms.rb", "test/test_if_modified_since.rb", "test/test_keep_alive.rb", "test/test_links.rb", "test/test_mech.rb", "test/test_mechanize_file.rb", "test/test_multi_select.rb", "test/test_no_attributes.rb", "test/test_option.rb", "test/test_page.rb", "test/test_pluggable_parser.rb", "test/test_post_form.rb", "test/test_pretty_print.rb", "test/test_radiobutton.rb", "test/test_redirect_limit_reached.rb", "test/test_redirect_verb_handling.rb", "test/test_referer.rb", "test/test_relative_links.rb", "test/test_response_code.rb", "test/test_save_file.rb", "test/test_scheme.rb", "test/test_select.rb", "test/test_select_all.rb", "test/test_select_none.rb", "test/test_select_noopts.rb", "test/test_set_fields.rb", "test/test_ssl_server.rb", "test/test_subclass.rb", "test/test_textarea.rb", "test/test_upload.rb", "test/test_verbs.rb"]
12
+ s.extra_rdoc_files = ["Manifest.txt", "CHANGELOG.rdoc", "EXAMPLES.rdoc", "FAQ.rdoc", "GUIDE.rdoc", "LICENSE.rdoc", "README.rdoc"]
13
+ s.files = ["CHANGELOG.rdoc", "EXAMPLES.rdoc", "FAQ.rdoc", "GUIDE.rdoc", "LICENSE.rdoc", "Manifest.txt", "README.rdoc", "Rakefile", "examples/flickr_upload.rb", "examples/mech-dump.rb", "examples/proxy_req.rb", "examples/rubyforge.rb", "examples/spider.rb", "lib/mechanize.rb", "lib/www/mechanize.rb", "lib/www/mechanize/chain.rb", "lib/www/mechanize/chain/auth_headers.rb", "lib/www/mechanize/chain/body_decoding_handler.rb", "lib/www/mechanize/chain/connection_resolver.rb", "lib/www/mechanize/chain/custom_headers.rb", "lib/www/mechanize/chain/handler.rb", "lib/www/mechanize/chain/header_resolver.rb", "lib/www/mechanize/chain/parameter_resolver.rb", "lib/www/mechanize/chain/post_connect_hook.rb", "lib/www/mechanize/chain/pre_connect_hook.rb", "lib/www/mechanize/chain/request_resolver.rb", "lib/www/mechanize/chain/response_body_parser.rb", "lib/www/mechanize/chain/response_header_handler.rb", "lib/www/mechanize/chain/response_reader.rb", "lib/www/mechanize/chain/ssl_resolver.rb", "lib/www/mechanize/chain/uri_resolver.rb", "lib/www/mechanize/content_type_error.rb", "lib/www/mechanize/cookie.rb", "lib/www/mechanize/cookie_jar.rb", "lib/www/mechanize/file.rb", "lib/www/mechanize/file_response.rb", "lib/www/mechanize/file_saver.rb", "lib/www/mechanize/form.rb", "lib/www/mechanize/form/button.rb", "lib/www/mechanize/form/check_box.rb", "lib/www/mechanize/form/field.rb", "lib/www/mechanize/form/file_upload.rb", "lib/www/mechanize/form/image_button.rb", "lib/www/mechanize/form/multi_select_list.rb", "lib/www/mechanize/form/option.rb", "lib/www/mechanize/form/radio_button.rb", "lib/www/mechanize/form/select_list.rb", "lib/www/mechanize/headers.rb", "lib/www/mechanize/history.rb", "lib/www/mechanize/inspect.rb", "lib/www/mechanize/monkey_patch.rb", "lib/www/mechanize/page.rb", "lib/www/mechanize/page/base.rb", "lib/www/mechanize/page/frame.rb", "lib/www/mechanize/page/link.rb", "lib/www/mechanize/page/meta.rb", "lib/www/mechanize/pluggable_parsers.rb", "lib/www/mechanize/redirect_limit_reached_error.rb", "lib/www/mechanize/redirect_not_get_or_head_error.rb", "lib/www/mechanize/response_code_error.rb", "lib/www/mechanize/unsupported_scheme_error.rb", "lib/www/mechanize/util.rb", "mechanize.gemspec", "test/chain/test_argument_validator.rb", "test/chain/test_custom_headers.rb", "test/chain/test_parameter_resolver.rb", "test/chain/test_request_resolver.rb", "test/chain/test_response_reader.rb", "test/data/htpasswd", "test/data/server.crt", "test/data/server.csr", "test/data/server.key", "test/data/server.pem", "test/helper.rb", "test/htdocs/alt_text.html", "test/htdocs/bad_form_test.html", "test/htdocs/button.jpg", "test/htdocs/empty_form.html", "test/htdocs/file_upload.html", "test/htdocs/find_link.html", "test/htdocs/form_multi_select.html", "test/htdocs/form_multival.html", "test/htdocs/form_no_action.html", "test/htdocs/form_no_input_name.html", "test/htdocs/form_select.html", "test/htdocs/form_select_all.html", "test/htdocs/form_select_none.html", "test/htdocs/form_select_noopts.html", "test/htdocs/form_set_fields.html", "test/htdocs/form_test.html", "test/htdocs/frame_test.html", "test/htdocs/google.html", "test/htdocs/iframe_test.html", "test/htdocs/index.html", "test/htdocs/link with space.html", "test/htdocs/meta_cookie.html", "test/htdocs/no_title_test.html", "test/htdocs/relative/tc_relative_links.html", "test/htdocs/tc_bad_links.html", "test/htdocs/tc_base_link.html", "test/htdocs/tc_blank_form.html", "test/htdocs/tc_checkboxes.html", "test/htdocs/tc_encoded_links.html", "test/htdocs/tc_follow_meta.html", "test/htdocs/tc_form_action.html", "test/htdocs/tc_links.html", "test/htdocs/tc_no_attributes.html", "test/htdocs/tc_pretty_print.html", "test/htdocs/tc_radiobuttons.html", "test/htdocs/tc_referer.html", "test/htdocs/tc_relative_links.html", "test/htdocs/tc_textarea.html", "test/htdocs/unusual______.html", "test/servlets.rb", "test/ssl_server.rb", "test/test_authenticate.rb", "test/test_bad_links.rb", "test/test_blank_form.rb", "test/test_checkboxes.rb", "test/test_content_type.rb", "test/test_cookie_class.rb", "test/test_cookie_jar.rb", "test/test_cookies.rb", "test/test_encoded_links.rb", "test/test_errors.rb", "test/test_follow_meta.rb", "test/test_form_action.rb", "test/test_form_as_hash.rb", "test/test_form_button.rb", "test/test_form_no_inputname.rb", "test/test_forms.rb", "test/test_frames.rb", "test/test_get_headers.rb", "test/test_gzipping.rb", "test/test_hash_api.rb", "test/test_history.rb", "test/test_history_added.rb", "test/test_html_unscape_forms.rb", "test/test_if_modified_since.rb", "test/test_keep_alive.rb", "test/test_links.rb", "test/test_mech.rb", "test/test_mechanize_file.rb", "test/test_multi_select.rb", "test/test_no_attributes.rb", "test/test_option.rb", "test/test_page.rb", "test/test_pluggable_parser.rb", "test/test_post_form.rb", "test/test_pretty_print.rb", "test/test_radiobutton.rb", "test/test_redirect_limit_reached.rb", "test/test_redirect_verb_handling.rb", "test/test_referer.rb", "test/test_relative_links.rb", "test/test_request.rb", "test/test_response_code.rb", "test/test_save_file.rb", "test/test_scheme.rb", "test/test_select.rb", "test/test_select_all.rb", "test/test_select_none.rb", "test/test_select_noopts.rb", "test/test_set_fields.rb", "test/test_ssl_server.rb", "test/test_subclass.rb", "test/test_textarea.rb", "test/test_upload.rb", "test/test_verbs.rb"]
14
14
  s.has_rdoc = true
15
15
  s.homepage = %q{ http://mechanize.rubyforge.org/}
16
- s.rdoc_options = ["--main", "README.txt"]
16
+ s.rdoc_options = ["--main", "README.rdoc"]
17
17
  s.require_paths = ["lib"]
18
18
  s.rubyforge_project = %q{mechanize}
19
19
  s.rubygems_version = %q{1.3.1}
20
20
  s.summary = %q{Mechanize provides automated web-browsing}
21
- s.test_files = ["test/chain/test_argument_validator.rb", "test/chain/test_custom_headers.rb", "test/chain/test_parameter_resolver.rb", "test/chain/test_request_resolver.rb", "test/chain/test_response_reader.rb", "test/test_authenticate.rb", "test/test_bad_links.rb", "test/test_blank_form.rb", "test/test_checkboxes.rb", "test/test_content_type.rb", "test/test_cookie_class.rb", "test/test_cookie_jar.rb", "test/test_cookies.rb", "test/test_encoded_links.rb", "test/test_errors.rb", "test/test_follow_meta.rb", "test/test_form_action.rb", "test/test_form_as_hash.rb", "test/test_form_button.rb", "test/test_form_no_inputname.rb", "test/test_forms.rb", "test/test_frames.rb", "test/test_get_headers.rb", "test/test_gzipping.rb", "test/test_hash_api.rb", "test/test_history.rb", "test/test_history_added.rb", "test/test_html_unscape_forms.rb", "test/test_if_modified_since.rb", "test/test_keep_alive.rb", "test/test_links.rb", "test/test_mech.rb", "test/test_mechanize_file.rb", "test/test_multi_select.rb", "test/test_no_attributes.rb", "test/test_option.rb", "test/test_page.rb", "test/test_pluggable_parser.rb", "test/test_post_form.rb", "test/test_pretty_print.rb", "test/test_radiobutton.rb", "test/test_redirect_limit_reached.rb", "test/test_redirect_verb_handling.rb", "test/test_referer.rb", "test/test_relative_links.rb", "test/test_response_code.rb", "test/test_save_file.rb", "test/test_scheme.rb", "test/test_select.rb", "test/test_select_all.rb", "test/test_select_none.rb", "test/test_select_noopts.rb", "test/test_set_fields.rb", "test/test_ssl_server.rb", "test/test_subclass.rb", "test/test_textarea.rb", "test/test_upload.rb", "test/test_verbs.rb"]
21
+ s.test_files = ["test/chain/test_argument_validator.rb", "test/chain/test_custom_headers.rb", "test/chain/test_parameter_resolver.rb", "test/chain/test_request_resolver.rb", "test/chain/test_response_reader.rb", "test/test_authenticate.rb", "test/test_bad_links.rb", "test/test_blank_form.rb", "test/test_checkboxes.rb", "test/test_content_type.rb", "test/test_cookie_class.rb", "test/test_cookie_jar.rb", "test/test_cookies.rb", "test/test_encoded_links.rb", "test/test_errors.rb", "test/test_follow_meta.rb", "test/test_form_action.rb", "test/test_form_as_hash.rb", "test/test_form_button.rb", "test/test_form_no_inputname.rb", "test/test_forms.rb", "test/test_frames.rb", "test/test_get_headers.rb", "test/test_gzipping.rb", "test/test_hash_api.rb", "test/test_history.rb", "test/test_history_added.rb", "test/test_html_unscape_forms.rb", "test/test_if_modified_since.rb", "test/test_keep_alive.rb", "test/test_links.rb", "test/test_mech.rb", "test/test_mechanize_file.rb", "test/test_multi_select.rb", "test/test_no_attributes.rb", "test/test_option.rb", "test/test_page.rb", "test/test_pluggable_parser.rb", "test/test_post_form.rb", "test/test_pretty_print.rb", "test/test_radiobutton.rb", "test/test_redirect_limit_reached.rb", "test/test_redirect_verb_handling.rb", "test/test_referer.rb", "test/test_relative_links.rb", "test/test_request.rb", "test/test_response_code.rb", "test/test_save_file.rb", "test/test_scheme.rb", "test/test_select.rb", "test/test_select_all.rb", "test/test_select_none.rb", "test/test_select_noopts.rb", "test/test_set_fields.rb", "test/test_ssl_server.rb", "test/test_subclass.rb", "test/test_textarea.rb", "test/test_upload.rb", "test/test_verbs.rb"]
22
22
 
23
23
  if s.respond_to? :specification_version then
24
24
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
25
  s.specification_version = 2
26
26
 
27
27
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
28
- s.add_runtime_dependency(%q<nokogiri>, [">= 1.0.7"])
29
- s.add_development_dependency(%q<hoe>, [">= 1.8.2"])
28
+ s.add_runtime_dependency(%q<nokogiri>, [">= 1.2.1"])
29
+ s.add_development_dependency(%q<hoe>, [">= 1.9.0"])
30
30
  else
31
- s.add_dependency(%q<nokogiri>, [">= 1.0.7"])
32
- s.add_dependency(%q<hoe>, [">= 1.8.2"])
31
+ s.add_dependency(%q<nokogiri>, [">= 1.2.1"])
32
+ s.add_dependency(%q<hoe>, [">= 1.9.0"])
33
33
  end
34
34
  else
35
- s.add_dependency(%q<nokogiri>, [">= 1.0.7"])
36
- s.add_dependency(%q<hoe>, [">= 1.8.2"])
35
+ s.add_dependency(%q<nokogiri>, [">= 1.2.1"])
36
+ s.add_dependency(%q<hoe>, [">= 1.9.0"])
37
37
  end
38
38
  end
@@ -59,6 +59,15 @@ class CookieClassTest < Test::Unit::TestCase
59
59
  end
60
60
  end
61
61
 
62
+ def test_parse_weird_cookie
63
+ cookie = 'n/a, ASPSESSIONIDCSRRQDQR=FBLDGHPBNDJCPCGNCPAENELB; path=/'
64
+ url = URI.parse('http://www.searchinnovation.com/')
65
+ WWW::Mechanize::Cookie.parse(url, cookie) { |cookie|
66
+ assert_equal('ASPSESSIONIDCSRRQDQR', cookie.name)
67
+ assert_equal('FBLDGHPBNDJCPCGNCPAENELB', cookie.value)
68
+ }
69
+ end
70
+
62
71
  def test_double_semicolon
63
72
  double_semi = 'WSIDC=WEST;; domain=.williams-sonoma.com; path=/'
64
73
  url = URI.parse('http://williams-sonoma.com/')
@@ -12,6 +12,28 @@ class FormsMechTest < Test::Unit::TestCase
12
12
  assert_match('/form_no_action.html?first=Aaron', page.uri.to_s)
13
13
  end
14
14
 
15
+ def test_submit_takes_arbirary_headers
16
+ page = @agent.get('http://localhost:2000/form_no_action.html')
17
+ assert form = page.forms.first
18
+ form.action = '/http_headers'
19
+ page = @agent.submit(form, nil, { 'foo' => 'bar' })
20
+ headers = Hash[*(
21
+ page.body.split("\n").map { |x| x.split('|') }.flatten
22
+ )]
23
+ assert_equal 'bar', headers['foo']
24
+ end
25
+
26
+ def test_submit_takes_arbirary_headers
27
+ page = @agent.get('http://localhost:2000/form_no_action.html')
28
+ assert form = page.forms.first
29
+ form.action = '/http_headers'
30
+ page = form.submit(nil, { 'foo' => 'bar' })
31
+ headers = Hash[*(
32
+ page.body.split("\n").map { |x| x.split('|') }.flatten
33
+ )]
34
+ assert_equal 'bar', headers['foo']
35
+ end
36
+
15
37
  # Test submitting form with two fields of the same name
16
38
  def test_post_multival
17
39
  page = @agent.get("http://localhost/form_multival.html")
@@ -72,6 +94,13 @@ class FormsMechTest < Test::Unit::TestCase
72
94
  assert_not_nil(page.link_with(:text => 'first:Patterson'))
73
95
  end
74
96
 
97
+ def test_post_with_non_strings
98
+ page = @agent.get("http://localhost/form_test.html")
99
+ page.form('post_form1') do |form|
100
+ form.first_name = 10
101
+ end.submit
102
+ end
103
+
75
104
  def test_post
76
105
  page = @agent.get("http://localhost/form_test.html")
77
106
  post_form = page.forms.find { |f| f.name == "post_form1" }
@@ -10,6 +10,17 @@ class TestMechMethods < Test::Unit::TestCase
10
10
  assert_equal('http://localhost/?foo=~2', page.uri.to_s)
11
11
  end
12
12
 
13
+ def test_submit_takes_arbirary_headers
14
+ page = @agent.get('http://localhost:2000/form_no_action.html')
15
+ assert form = page.forms.first
16
+ form.action = '/http_headers'
17
+ page = @agent.submit(form, nil, { 'foo' => 'bar' })
18
+ headers = Hash[*(
19
+ page.body.split("\n").map { |x| x.split('|') }.flatten
20
+ )]
21
+ assert_equal 'bar', headers['foo']
22
+ end
23
+
13
24
  def test_get_with_params
14
25
  page = @agent.get('http://localhost/', { :q => 'hello' })
15
26
  assert_equal('http://localhost/?q=hello', page.uri.to_s)
@@ -1,10 +1,28 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
2
2
 
3
+ require 'cgi'
4
+
3
5
  class TestPage < Test::Unit::TestCase
4
6
  def setup
5
7
  @agent = WWW::Mechanize.new
6
8
  end
7
9
 
10
+ def test_broken_charset
11
+ page = @agent.get("http://localhost/http_headers?content-type=#{CGI.escape('text/html; charset=akldsjfhaldjfksh')}")
12
+ assert page.parser
13
+ end
14
+
15
+ def test_upper_case_content_type
16
+ page = @agent.get("http://localhost/http_headers?content-type=#{CGI.escape('text/HTML')}")
17
+ assert_instance_of WWW::Mechanize::Page, page
18
+ assert_equal 'text/HTML', page.content_type
19
+ end
20
+
21
+ def test_page_gets_charset_sent_by_server
22
+ page = @agent.get("http://localhost/http_headers?content-type=#{CGI.escape('text/html; charset=UTF-8')}")
23
+ assert_equal 'UTF-8', page.encoding
24
+ end
25
+
8
26
  def test_set_encoding
9
27
  page = @agent.get("http://localhost/file_upload.html")
10
28
  page.encoding = 'UTF-8'
@@ -60,4 +60,16 @@ class TestRadioButtons < Test::Unit::TestCase
60
60
  ).checked)
61
61
  end
62
62
  end
63
+
64
+ def test_click_all
65
+ form = @page.forms.first
66
+ form.radiobuttons_with(:name => 'color').each do |button|
67
+ button.click
68
+ end
69
+ c = form.radiobuttons_with(:name => 'color').inject(0) do |m,button|
70
+ m += 1 if button.checked
71
+ m
72
+ end
73
+ assert_equal 1, c, 'Only one radio button should be checked'
74
+ end
63
75
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mechanize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Patterson
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-02-23 00:00:00 -08:00
13
+ date: 2009-03-05 00:00:00 -08:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -42,21 +42,21 @@ executables: []
42
42
  extensions: []
43
43
 
44
44
  extra_rdoc_files:
45
- - EXAMPLES.txt
46
- - FAQ.txt
47
- - GUIDE.txt
48
- - History.txt
49
- - LICENSE.txt
50
45
  - Manifest.txt
51
- - README.txt
46
+ - CHANGELOG.rdoc
47
+ - EXAMPLES.rdoc
48
+ - FAQ.rdoc
49
+ - GUIDE.rdoc
50
+ - LICENSE.rdoc
51
+ - README.rdoc
52
52
  files:
53
- - EXAMPLES.txt
54
- - FAQ.txt
55
- - GUIDE.txt
56
- - History.txt
57
- - LICENSE.txt
53
+ - CHANGELOG.rdoc
54
+ - EXAMPLES.rdoc
55
+ - FAQ.rdoc
56
+ - GUIDE.rdoc
57
+ - LICENSE.rdoc
58
58
  - Manifest.txt
59
- - README.txt
59
+ - README.rdoc
60
60
  - Rakefile
61
61
  - examples/flickr_upload.rb
62
62
  - examples/mech-dump.rb
@@ -224,7 +224,7 @@ homepage: " http://mechanize.rubyforge.org/"
224
224
  post_install_message:
225
225
  rdoc_options:
226
226
  - --main
227
- - README.txt
227
+ - README.rdoc
228
228
  require_paths:
229
229
  - lib
230
230
  required_ruby_version: !ruby/object:Gem::Requirement