mechanize 2.7.3 → 2.7.4

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.

Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +15 -0
  3. data/.travis.yml +5 -6
  4. data/CHANGELOG.rdoc +22 -0
  5. data/EXAMPLES.rdoc +1 -1
  6. data/Gemfile +3 -0
  7. data/Manifest.txt +0 -1
  8. data/README.rdoc +11 -17
  9. data/Rakefile +22 -38
  10. data/examples/{rubyforge.rb → rubygems.rb} +5 -4
  11. data/lib/mechanize.rb +72 -31
  12. data/lib/mechanize/directory_saver.rb +14 -2
  13. data/lib/mechanize/element_matcher.rb +24 -13
  14. data/lib/mechanize/file_response.rb +1 -3
  15. data/lib/mechanize/form.rb +8 -2
  16. data/lib/mechanize/http/agent.rb +38 -30
  17. data/lib/mechanize/http/auth_store.rb +2 -0
  18. data/lib/mechanize/http/www_authenticate_parser.rb +1 -1
  19. data/lib/mechanize/page.rb +162 -54
  20. data/lib/mechanize/page/image.rb +2 -0
  21. data/lib/mechanize/page/link.rb +5 -0
  22. data/lib/mechanize/pluggable_parsers.rb +13 -1
  23. data/lib/mechanize/test_case.rb +5 -0
  24. data/lib/mechanize/unsupported_scheme_error.rb +4 -2
  25. data/lib/mechanize/util.rb +88 -43
  26. data/lib/mechanize/version.rb +3 -0
  27. data/mechanize.gemspec +61 -0
  28. data/test/test_mechanize.rb +55 -41
  29. data/test/test_mechanize_form.rb +19 -0
  30. data/test/test_mechanize_form_encoding.rb +2 -7
  31. data/test/test_mechanize_http_agent.rb +61 -12
  32. data/test/test_mechanize_http_www_authenticate_parser.rb +8 -0
  33. data/test/test_mechanize_link.rb +14 -1
  34. data/test/test_mechanize_page.rb +53 -6
  35. data/test/test_mechanize_page_encoding.rb +2 -3
  36. data/test/test_mechanize_page_link.rb +17 -2
  37. data/test/test_mechanize_util.rb +45 -10
  38. metadata +147 -72
  39. data/.gemtest +0 -0
  40. data/lib/mechanize/monkey_patch.rb +0 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c12fbfdafc2cf8b5e94edf3db704c3ed421331f9
4
- data.tar.gz: 0993d3a38d4241baa07167ba77a74cdd378e58fd
3
+ metadata.gz: f74b81c4883e990cd6360ee0294a3ff1ae1c8d59
4
+ data.tar.gz: 872ab6eeda86c290a94105a730bfec64ee819493
5
5
  SHA512:
6
- metadata.gz: 3f07973adedd7639b1dd91e37c91ec7d74a1d5ad85ff87b2668f7ecedd30c0e12d6a954b3fe3634764a29f745cec6084eb83b795fd9ee46203d8b8653d0f3cb1
7
- data.tar.gz: a89b922deb0fd98ba15d35a7a130e28b373082d3a9505885594bb8c4689b5014cbf6a46238385bd9d046ce8f6ba42abc552c2cf97f90acc2b6521722463f3b3e
6
+ metadata.gz: 96dc6beaa52babf27369eb8548733298782a2409f7a2bb43c9a5e9241445d96e117c54ad5b8c3e445b6b4c4ea1edb37f8b223b0513916f8be7b591fa3e29c598
7
+ data.tar.gz: 95e653b7705518a33aa5bbb765be7ddc4603756e0ee24bd5ab6c2979d039ea5b29e94ae9a2b8e478ceaa993b165d83a65d695212fa271ab59889fe7c811c876d
@@ -0,0 +1,15 @@
1
+ *.swp
2
+ *.gem
3
+ *.rbc
4
+ /.bundle
5
+ /.config
6
+ /Gemfile.lock
7
+ /TAGS
8
+ /pkg
9
+ /tags
10
+ /.rvmrc
11
+ digest.htpasswd
12
+ doc
13
+ rdoc
14
+ .yardoc
15
+ _yardoc
@@ -1,23 +1,22 @@
1
1
  ---
2
- after_script:
3
- - rake travis:after -t
4
- before_script:
5
- - gem install hoe-travis --no-rdoc --no-ri
6
- - rake travis:before -t
7
2
  language: ruby
8
3
  notifications:
9
4
  email:
10
5
  - drbrain@segment7.net
11
6
  - ljjarvis@gmail.com
12
7
  - knu@idaemons.org
8
+ sudo: false
13
9
  rvm:
14
10
  - 1.9.3
15
11
  - 2.0.0
12
+ - 2.1
13
+ - 2.2
14
+ - 2.3
16
15
  - ruby-head
17
16
  - jruby-19mode
18
17
  - jruby-head
19
18
  - rbx-19mode
20
- script: rake travis
19
+ script: rake test
21
20
  matrix:
22
21
  allow_failures:
23
22
  - rvm: ruby-head
@@ -1,5 +1,27 @@
1
1
  = Mechanize CHANGELOG
2
2
 
3
+ === 2.7.4
4
+
5
+ * New Features
6
+ * Accept array-like and hash-like values as query/parameter value.
7
+ A new utility method Mechanize::Util.each_parameter is added, and Mechanize::Util.build_query_string is enhanced
8
+ for this feature.
9
+ * Allow passing a `Form::FileUpload` instance to `#post`. #350 by Sam
10
+ Rawlins.
11
+ * Capture link when scheme is unsupported. #362 by Jon Rowe.
12
+ * Pre-defined User-Agent stings are updated to those of more recent versions, and new aliases for IE 10/11 and Edge are added.
13
+ * Support for mime-types 1.x is restored while keeping compatible with mime-types 2.x and adding support for 3.0.
14
+ * Mechanize::Page now responds to #xpath, #css, #at_xpath, #at_css, and #%.
15
+ * element(s)_with methods now accept :xpath and :css options for doing xpath/css
16
+ selector searching.
17
+ * Pass URI information to Nokogiri where applicable. #405 @lulalala
18
+
19
+ * Bug fix
20
+ * Don't raise an exception if a connection has set a {read,open}_timeout and
21
+ a `file://` request is made. (#397)
22
+ * Fix whitespace bug in WWW-Authenticate. #451, #450, by Rasmus Bergholdt
23
+ * Don't allow redirect from a non-file URL to a file URL for security reasons. (#455)
24
+
3
25
  === 2.7.3
4
26
 
5
27
  * New Features
@@ -15,7 +15,7 @@ example, <code>do ... end.submit</code> is the same as <code>{ ...
15
15
  }
16
16
 
17
17
  a.get('http://google.com/') do |page|
18
- search_result = page.form_with(:name => 'f') do |search|
18
+ search_result = page.form_with(:id => 'gbqf') do |search|
19
19
  search.q = 'Hello world'
20
20
  end.submit
21
21
 
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -53,7 +53,6 @@ lib/mechanize/http/auth_store.rb
53
53
  lib/mechanize/http/content_disposition_parser.rb
54
54
  lib/mechanize/http/www_authenticate_parser.rb
55
55
  lib/mechanize/image.rb
56
- lib/mechanize/monkey_patch.rb
57
56
  lib/mechanize/page.rb
58
57
  lib/mechanize/page/base.rb
59
58
  lib/mechanize/page/frame.rb
@@ -1,6 +1,6 @@
1
- = Mechanize {<img src="https://secure.travis-ci.org/sparklemotion/mechanize.png?rvm=1.9.3" />}[http://travis-ci.org/sparklemotion/mechanize]
1
+ = Mechanize {<img src="https://secure.travis-ci.org/sparklemotion/mechanize.svg?rvm=1.9.3" />}[http://travis-ci.org/sparklemotion/mechanize]
2
2
 
3
- * http://mechanize.rubyforge.org
3
+ * http://docs.seattlerb.org/mechanize
4
4
  * https://github.com/sparklemotion/mechanize
5
5
 
6
6
  == Description
@@ -14,32 +14,26 @@ a history.
14
14
  == Dependencies
15
15
 
16
16
  * ruby 1.9.2 or newer
17
- * nokogiri[http://nokogiri.rubyforge.org]
17
+ * nokogiri[https://github.com/sparklemotion/nokogiri]
18
18
 
19
19
  == Support:
20
20
 
21
- The mechanize mailing list is available here:
22
-
23
- * http://rubyforge.org/mailman/listinfo/mechanize-users
24
-
25
21
  The bug tracker is available here:
26
22
 
27
23
  * https://github.com/sparklemotion/mechanize/issues
28
24
 
29
25
  == Examples
30
26
 
31
- If you are just starting, check out the GUIDE[http://mechanize.rubyforge.org/GUIDE_rdoc.html] or
32
- the EXAMPLES[http://mechanize.rubyforge.org/EXAMPLES_rdoc.html] file.
27
+ If you are just starting, check out the GUIDE[http://docs.seattlerb.org/mechanize/GUIDE_rdoc.html] or
28
+ the EXAMPLES[http://docs.seattlerb.org/mechanize/EXAMPLES_rdoc.html] file.
33
29
 
34
30
  == Developers
35
31
 
36
- To run the tests for the first time:
32
+ Use bundler to install dependencies:
37
33
 
38
- gem install hoe rake
39
- rake newb
34
+ bundle install
40
35
 
41
- This will install all the required dependencies for running the tests. For
42
- subsequent test runs:
36
+ Run all tests with:
43
37
 
44
38
  rake test
45
39
 
@@ -57,11 +51,11 @@ Copyright (c) 2006-2011:
57
51
  * {Aaron Patterson}[http://tenderlovemaking.com] (aaronp@rubyforge.org)
58
52
  * {Mike Dalessio}[http://mike.daless.io] (mike@csa.net)
59
53
 
60
- Copyright (c) 2011-2013:
54
+ Copyright (c) 2011-2015:
61
55
 
62
56
  * {Eric Hodel}[http://blog.segment7.net] (drbrain@segment7.net)
63
57
  * {Akinori MUSHA}[http://blog.akinori.org] (knu@idaemons.org)
64
- * {Lee Jarvis}[http://aeroproof.com] (ljjarvis@gmail.com)
58
+ * {Lee Jarvis}[http://twitter.com/lee_jarvis] (ljjarvis@gmail.com)
65
59
 
66
60
  This library comes with a shameless plug for employing me
67
61
  (Aaron[http://tenderlovemaking.com/]) programming Ruby, my favorite language!
@@ -79,5 +73,5 @@ library!
79
73
 
80
74
  == License
81
75
 
82
- This library is distributed under the MIT license. Please see the LICENSE[http://mechanize.rubyforge.org/LICENSE_rdoc.html] file.
76
+ This library is distributed under the MIT license. Please see the LICENSE[http://docs.seattlerb.org/mechanize/LICENSE_rdoc.html] file.
83
77
 
data/Rakefile CHANGED
@@ -1,38 +1,14 @@
1
1
  require 'rubygems'
2
- require 'hoe'
3
2
 
4
- Hoe.plugin :git
5
- Hoe.plugin :minitest
6
- Hoe.plugin :travis
7
-
8
- hoe = Hoe.spec 'mechanize' do
9
- developer 'Eric Hodel', 'drbrain@segment7.net'
10
- developer 'Aaron Patterson', 'aaronp@rubyforge.org'
11
- developer 'Mike Dalessio', 'mike.dalessio@gmail.com'
12
- developer 'Akinori MUSHA', 'knu@idaemons.org'
13
- developer 'Lee Jarvis', 'ljjarvis@gmail.com'
14
-
15
- self.readme_file = 'README.rdoc'
16
- self.history_file = 'CHANGELOG.rdoc'
17
- self.extra_rdoc_files += Dir['*.rdoc']
18
-
19
- rdoc_locations << 'rubyforge.org:/var/www/gforge-projects/mechanize/'
20
-
21
- self.extra_deps << ['net-http-digest_auth', '~> 1.1', '>= 1.1.1']
22
- self.extra_deps << ['net-http-persistent', '~> 2.5', '>= 2.5.2']
23
- self.extra_deps << ['mime-types', '~> 2.0']
24
- self.extra_deps << ['http-cookie', '~> 1.0']
25
- self.extra_deps << ['nokogiri', '~> 1.4']
26
- self.extra_deps << ['ntlm-http', '~> 0.1', '>= 0.1.1']
27
- self.extra_deps << ['webrobots', '< 0.2', '>= 0.0.9']
28
- self.extra_deps << ['domain_name', '~> 0.5', '>= 0.5.1']
29
-
30
- self.extra_dev_deps << ['minitest', '~> 5.0']
31
-
32
- self.spec_extras[:required_ruby_version] = '>= 1.8.7'
3
+ begin
4
+ require "bundler/gem_tasks"
5
+ rescue LoadError
33
6
  end
34
7
 
35
- task :prerelease => [:clobber, :check_manifest, :test]
8
+ require 'rdoc/task'
9
+ require 'rake/testtask'
10
+
11
+ task :prerelease => [:clobber_rdoc, :test]
36
12
 
37
13
  desc "Update SSL Certificate"
38
14
  task('ssl_cert') do |p|
@@ -46,12 +22,20 @@ task('ssl_cert') do |p|
46
22
  sh "rm server.key.org"
47
23
  end
48
24
 
49
- desc 'Install deps for travis to work around Hoe/RubyGems bug'
50
- task 'travis_deps' do
51
- hoe.spec.dependencies.each do |dep|
52
- first_requirement = dep.requirement.requirements.first.join ' '
53
- system('gem', 'install', dep.name, '-v', first_requirement,
54
- '--no-rdoc', '--no-ri')
55
- end
25
+ RDoc::Task.new do |rdoc|
26
+ rdoc.main = "README.rdoc"
27
+ rdoc.rdoc_dir = 'doc'
28
+ rdoc.rdoc_files.include( "CHANGELOG.rdoc", "EXAMPLES.rdoc", "GUIDE.rdoc", "LICENSE.rdoc", "Manifest.txt", "README.rdoc", "lib/**/*.rb")
29
+ end
30
+
31
+ desc "Run tests"
32
+ Rake::TestTask.new { |t|
33
+ t.test_files = Dir['test/**/test*.rb']
34
+ t.verbose = true
35
+ }
36
+
37
+ task publish_docs: %w[rdoc] do
38
+ sh 'rsync', '-avzO', '--delete', 'doc/', 'docs-push.seattlerb.org:/data/www/docs.seattlerb.org/mechanize/'
56
39
  end
57
40
 
41
+ task default: :test
@@ -10,11 +10,12 @@ mech.log = Logger.new $stderr
10
10
  mech.agent.http.debug_output = $stderr
11
11
 
12
12
  # Load the rubyforge website
13
- page = mech.get('http://rubyforge.org/')
14
- page = mech.click page.link_with(:text => /Log In/) # Click the login link
13
+ page = mech.get('https://rubygems.org/')
14
+ page = mech.click page.link_with(:text => /Sign in/) # Click the login link
15
15
  form = page.forms[1] # Select the first form
16
- form.form_loginname = ARGV[0]
17
- form.form_pw = ARGV[1]
16
+ form["session[who]"] = ARGV[0]
17
+ form["session[password]"] = ARGV[1]
18
+ form["commit"] = "Sign in"
18
19
 
19
20
  # Submit the form
20
21
  page = form.submit form.buttons.first
@@ -1,7 +1,6 @@
1
+ require 'mechanize/version'
1
2
  require 'fileutils'
2
3
  require 'forwardable'
3
- require 'iconv' if RUBY_VERSION < '1.9.2'
4
- require 'mime/types'
5
4
  require 'mutex_m'
6
5
  require 'net/http/digest_auth'
7
6
  require 'net/http/persistent'
@@ -70,11 +69,6 @@ require 'zlib'
70
69
 
71
70
  class Mechanize
72
71
 
73
- ##
74
- # The version of Mechanize you are using.
75
-
76
- VERSION = '2.7.3'
77
-
78
72
  ##
79
73
  # Base mechanize error class
80
74
 
@@ -92,22 +86,26 @@ class Mechanize
92
86
  # description in parenthesis is for informative purposes and is not part of
93
87
  # the alias name.
94
88
  #
95
- # * Linux Firefox (3.6.1)
89
+ # * Linux Firefox (43.0 on Ubuntu Linux)
96
90
  # * Linux Konqueror (3)
97
91
  # * Linux Mozilla
98
- # * Mac Firefox (3.6)
92
+ # * Mac Firefox (43.0)
99
93
  # * Mac Mozilla
100
- # * Mac Safari (5)
94
+ # * Mac Safari (9.0 on OS X 10.11.2)
101
95
  # * Mac Safari 4
102
96
  # * Mechanize (default)
103
97
  # * Windows IE 6
104
98
  # * Windows IE 7
105
99
  # * Windows IE 8
106
100
  # * Windows IE 9
101
+ # * Windows IE 10 (Windows 8 64bit)
102
+ # * Windows IE 11 (Windows 8.1 64bit)
103
+ # * Windows Edge
107
104
  # * Windows Mozilla
108
- # * iPhone (3.0)
109
- # * iPad
110
- # * Android (Motorola Xoom)
105
+ # * Windows Firefox (43.0)
106
+ # * iPhone (iOS 9.1)
107
+ # * iPad (iOS 9.1)
108
+ # * Android (5.1.1)
111
109
  #
112
110
  # Example:
113
111
  #
@@ -116,26 +114,37 @@ class Mechanize
116
114
 
117
115
  AGENT_ALIASES = {
118
116
  'Mechanize' => "Mechanize/#{VERSION} Ruby/#{ruby_version} (http://github.com/sparklemotion/mechanize/)",
119
- 'Linux Firefox' => 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.1) Gecko/20100122 firefox/3.6.1',
117
+ 'Linux Firefox' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:43.0) Gecko/20100101 Firefox/43.0',
120
118
  'Linux Konqueror' => 'Mozilla/5.0 (compatible; Konqueror/3; Linux)',
121
119
  'Linux Mozilla' => 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030624',
122
- 'Mac Firefox' => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6',
120
+ 'Mac Firefox' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:43.0) Gecko/20100101 Firefox/43.0',
123
121
  'Mac Mozilla' => 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.4a) Gecko/20030401',
124
122
  'Mac Safari 4' => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2; de-at) AppleWebKit/531.21.8 (KHTML, like Gecko) Version/4.0.4 Safari/531.21.10',
125
- 'Mac Safari' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/534.51.22 (KHTML, like Gecko) Version/5.1.1 Safari/534.51.22',
126
- 'Windows Chrome' => 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.32 Safari/537.36',
123
+ 'Mac Safari' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/601.3.9 (KHTML, like Gecko) Version/9.0.2 Safari/601.3.9',
124
+ 'Windows Chrome' => 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.125 Safari/537.36',
127
125
  'Windows IE 6' => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)',
128
126
  'Windows IE 7' => 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)',
129
127
  'Windows IE 8' => 'Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727)',
130
128
  'Windows IE 9' => 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)',
129
+ 'Windows IE 10' => 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)',
130
+ 'Windows IE 11' => 'Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko',
131
+ 'Windows Edge' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586',
131
132
  'Windows Mozilla' => 'Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4b) Gecko/20030516 Mozilla Firebird/0.6',
132
- 'iPhone' => 'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1C28 Safari/419.3',
133
- 'iPad' => 'Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10',
134
- 'Android' => 'Mozilla/5.0 (Linux; U; Android 3.0; en-us; Xoom Build/HRI39) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13'
133
+ 'Windows Firefox' => 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0',
134
+ 'iPhone' => 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B5110e Safari/601.1',
135
+ 'iPad' => 'Mozilla/5.0 (iPad; CPU OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1',
136
+ 'Android' => 'Mozilla/5.0 (Linux; Android 5.1.1; Nexus 7 Build/LMY47V) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.76 Safari/537.36',
135
137
  }
136
138
 
137
- AGENT_ALIASES['Mac FireFox'] = AGENT_ALIASES['Mac Firefox']
138
- AGENT_ALIASES['Linux FireFox'] = AGENT_ALIASES['Linux Firefox']
139
+ AGENT_ALIASES.default_proc = proc { |hash, key|
140
+ case key
141
+ when /FireFox/
142
+ if ua = hash[nkey = key.sub(/FireFox/, 'Firefox')]
143
+ warn "Mechanize#user_agent_alias: #{key.inspect} should be spelled as #{nkey.inspect}"
144
+ ua
145
+ end
146
+ end
147
+ }
139
148
 
140
149
  def self.inherited(child) # :nodoc:
141
150
  child.html_parser = html_parser
@@ -342,12 +351,21 @@ class Mechanize
342
351
  click real_link
343
352
  else
344
353
  button = nil
354
+ # Note that this will not work if we have since navigated to a different page.
355
+ # Should rather make each button aware of its parent form.
345
356
  form = page.forms.find do |f|
346
357
  button = f.button_with(:value => link)
347
358
  button.is_a? Form::Submit
348
359
  end
349
360
  submit form, button if form
350
361
  end
362
+ when Form::Submit, Form::ImageButton then
363
+ # Note that this will not work if we have since navigated to a different page.
364
+ # Should rather make each button aware of its parent form.
365
+ form = page.forms.find do |f|
366
+ f.buttons.include?(link)
367
+ end
368
+ submit form, link if form
351
369
  else
352
370
  referer = current_page()
353
371
  href = link.respond_to?(:href) ? link.href :
@@ -400,6 +418,9 @@ class Mechanize
400
418
  ##
401
419
  # DELETE +uri+ with +query_params+, and setting +headers+:
402
420
  #
421
+ # +query_params+ is formatted into a query string using
422
+ # Mechanize::Util.build_query_string, which see.
423
+ #
403
424
  # delete('http://example/', {'q' => 'foo'}, {})
404
425
 
405
426
  def delete(uri, query_params = {}, headers = {})
@@ -413,6 +434,9 @@ class Mechanize
413
434
  # +headers+.
414
435
  #
415
436
  # The +referer+ may be a URI or a page.
437
+ #
438
+ # +parameters+ is formatted into a query string using
439
+ # Mechanize::Util.build_query_string, which see.
416
440
 
417
441
  def get(uri, parameters = [], referer = nil, headers = {})
418
442
  method = :get
@@ -453,6 +477,9 @@ class Mechanize
453
477
  ##
454
478
  # HEAD +uri+ with +query_params+ and +headers+:
455
479
  #
480
+ # +query_params+ is formatted into a query string using
481
+ # Mechanize::Util.build_query_string, which see.
482
+ #
456
483
  # head('http://example/', {'q' => 'foo'}, {})
457
484
 
458
485
  def head(uri, query_params = {}, headers = {})
@@ -464,9 +491,13 @@ class Mechanize
464
491
  end
465
492
 
466
493
  ##
467
- # POST to the given +uri+ with the given +query+. The query is specified by
468
- # either a string, or a list of key-value pairs represented by a hash or an
469
- # array of arrays.
494
+ # POST to the given +uri+ with the given +query+.
495
+ #
496
+ # +query+ is processed using Mechanize::Util.each_parameter (which
497
+ # see), and then encoded into an entity body. If any IO/FileUpload
498
+ # object is specified as a field value the "enctype" will be
499
+ # multipart/form-data, or application/x-www-form-urlencoded
500
+ # otherwise.
470
501
  #
471
502
  # Examples:
472
503
  # agent.post 'http://example.com/', "foo" => "bar"
@@ -489,12 +520,15 @@ class Mechanize
489
520
 
490
521
  form = Form.new(node)
491
522
 
492
- query.each { |k, v|
523
+ Mechanize::Util.each_parameter(query) { |k, v|
493
524
  if v.is_a?(IO)
494
525
  form.enctype = 'multipart/form-data'
495
526
  ul = Form::FileUpload.new({'name' => k.to_s},::File.basename(v.path))
496
527
  ul.file_data = v.read
497
528
  form.file_uploads << ul
529
+ elsif v.is_a?(Form::FileUpload)
530
+ form.enctype = 'multipart/form-data'
531
+ form.file_uploads << v
498
532
  else
499
533
  form.fields << Form::Field.new({'name' => k.to_s},v)
500
534
  end
@@ -518,6 +552,8 @@ class Mechanize
518
552
  def request_with_entity(verb, uri, entity, headers = {})
519
553
  cur_page = current_page || Page.new
520
554
 
555
+ log.debug("query: #{ entity.inspect }") if log
556
+
521
557
  headers = {
522
558
  'Content-Type' => 'application/octet-stream',
523
559
  'Content-Length' => entity.size.to_s,
@@ -934,6 +970,12 @@ Use of #auth and #basic_auth are deprecated due to a security vulnerability.
934
970
  @agent.redirection_limit = limit
935
971
  end
936
972
 
973
+ ##
974
+ # Resolve the full path of a link / uri
975
+ def resolve link
976
+ @agent.resolve link
977
+ end
978
+
937
979
  ##
938
980
  # A hash of custom request headers that will be sent on every request
939
981
 
@@ -1138,19 +1180,19 @@ Use of #auth and #basic_auth are deprecated due to a security vulnerability.
1138
1180
  end
1139
1181
 
1140
1182
  ##
1141
- # SSL version to use. Ruby 1.9 and newer only.
1183
+ # SSL version to use.
1142
1184
 
1143
1185
  def ssl_version
1144
1186
  @agent.ssl_version
1145
- end if RUBY_VERSION > '1.9'
1187
+ end
1146
1188
 
1147
1189
  ##
1148
1190
  # Sets the SSL version to use to +version+ without client/server
1149
- # negotiation. Ruby 1.9 and newer only.
1191
+ # negotiation.
1150
1192
 
1151
1193
  def ssl_version= ssl_version
1152
1194
  @agent.ssl_version = ssl_version
1153
- end if RUBY_VERSION > '1.9'
1195
+ end
1154
1196
 
1155
1197
  ##
1156
1198
  # A callback for additional certificate verification. See
@@ -1316,7 +1358,6 @@ require 'mechanize/http/content_disposition_parser'
1316
1358
  require 'mechanize/http/www_authenticate_parser'
1317
1359
  require 'mechanize/image'
1318
1360
  require 'mechanize/page'
1319
- require 'mechanize/monkey_patch'
1320
1361
  require 'mechanize/pluggable_parsers'
1321
1362
  require 'mechanize/redirect_limit_reached_error'
1322
1363
  require 'mechanize/redirect_not_get_or_head_error'