tenderlove-mechanize 0.9.3.20090617085936 → 0.9.3.20090623142847

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -2,9 +2,17 @@
2
2
 
3
3
  === HEAD
4
4
 
5
+ * Bug Fixes:
6
+
7
+ * Rescue errors from bogus encodings
8
+
9
+ === 0.9.3
10
+
5
11
  * Bug Fixes:
6
12
 
7
13
  * Do not apply encoding if encoding equals 'none' Thanks Akinori MUSHA!
14
+ * Fixed Page#encoding= when changing the value from or to nil. Made
15
+ it return the assigned value while at it. (Akinori MUSHA)
8
16
  * Custom request headers may be supplied WWW::Mechanize#request_headers
9
17
  RF #24516
10
18
  * HTML Parser may be set on a per instance level WWW::Mechanize#html_parser
@@ -24,15 +24,15 @@ module WWW
24
24
  # puts form['name']
25
25
  class Form
26
26
  attr_accessor :method, :action, :name
27
-
27
+
28
28
  attr_reader :fields, :buttons, :file_uploads, :radiobuttons, :checkboxes
29
29
  attr_accessor :enctype
30
30
 
31
31
  alias :elements :fields
32
-
32
+
33
33
  attr_reader :form_node
34
34
  attr_reader :page
35
-
35
+
36
36
  def initialize(node, mech=nil, page=nil)
37
37
  @enctype = node['enctype'] || 'application/x-www-form-urlencoded'
38
38
  @form_node = node
@@ -137,10 +137,10 @@ module WWW
137
137
  end
138
138
 
139
139
  # This method is sub-method of build_query.
140
- # It converts charset of query value of fields into excepted one.
140
+ # It converts charset of query value of fields into expected one.
141
141
  def proc_query(field)
142
142
  return unless field.query_value
143
- field.query_value.map{|(name, val)|
143
+ field.query_value.map{|(name, val)|
144
144
  [from_native_charset(name), from_native_charset(val.to_s)]
145
145
  }
146
146
  end
@@ -149,7 +149,7 @@ module WWW
149
149
  def from_native_charset(str, enc=nil)
150
150
  if page
151
151
  enc ||= page.encoding
152
- Util.from_native_charset(str,enc)
152
+ Util.from_native_charset(str,enc) rescue str
153
153
  else
154
154
  str
155
155
  end
@@ -161,36 +161,36 @@ module WWW
161
161
  # be used to create a query string for this form.
162
162
  def build_query(buttons = [])
163
163
  query = []
164
-
164
+
165
165
  fields().each do |f|
166
166
  qval = proc_query(f)
167
167
  query.push(*qval)
168
168
  end
169
-
169
+
170
170
  checkboxes().each do |f|
171
171
  if f.checked
172
172
  qval = proc_query(f)
173
173
  query.push(*qval)
174
174
  end
175
175
  end
176
-
176
+
177
177
  radio_groups = {}
178
178
  radiobuttons().each do |f|
179
179
  fname = from_native_charset(f.name)
180
180
  radio_groups[fname] ||= []
181
- radio_groups[fname] << f
181
+ radio_groups[fname] << f
182
182
  end
183
-
183
+
184
184
  # take one radio button from each group
185
185
  radio_groups.each_value do |g|
186
186
  checked = g.select {|f| f.checked}
187
-
187
+
188
188
  if checked.size == 1
189
189
  f = checked.first
190
190
  qval = proc_query(f)
191
191
  query.push(*qval)
192
- elsif checked.size > 1
193
- raise "multiple radiobuttons are checked in the same group!"
192
+ elsif checked.size > 1
193
+ raise "multiple radiobuttons are checked in the same group!"
194
194
  end
195
195
  end
196
196
 
@@ -206,7 +206,7 @@ module WWW
206
206
  def add_button_to_query(button)
207
207
  @clicked_buttons << button
208
208
  end
209
-
209
+
210
210
  # This method calculates the request data to be sent back to the server
211
211
  # for this form, depending on if this is a regular post, get, or a
212
212
  # multi-part post,
@@ -225,8 +225,8 @@ module WWW
225
225
  WWW::Mechanize::Util.build_query_string(query_params)
226
226
  end
227
227
  end
228
-
229
- # Removes all fields with name +field_name+.
228
+
229
+ # Removes all fields with name +field_name+.
230
230
  def delete_field!(field_name)
231
231
  @fields.delete_if{ |f| f.name == field_name}
232
232
  end
@@ -255,7 +255,7 @@ module WWW
255
255
  alias :#{singular} :#{singular}_with
256
256
  eomethod
257
257
  end
258
-
258
+
259
259
  private
260
260
  def parse
261
261
  @fields = []
@@ -263,7 +263,7 @@ module WWW
263
263
  @file_uploads = []
264
264
  @radiobuttons = []
265
265
  @checkboxes = []
266
-
266
+
267
267
  # Find all input tags
268
268
  form_node.search('input').each do |node|
269
269
  type = (node['type'] || 'text').downcase
@@ -275,7 +275,7 @@ module WWW
275
275
  when 'checkbox'
276
276
  @checkboxes << CheckBox.new(node['name'], node['value'], !!node['checked'], self)
277
277
  when 'file'
278
- @file_uploads << FileUpload.new(node['name'], nil)
278
+ @file_uploads << FileUpload.new(node['name'], nil)
279
279
  when 'submit'
280
280
  @buttons << Button.new(node['name'], node['value'])
281
281
  when 'button'
@@ -283,7 +283,7 @@ module WWW
283
283
  when 'image'
284
284
  @buttons << ImageButton.new(node['name'], node['value'])
285
285
  else
286
- @fields << Field.new(node['name'], node['value'] || '')
286
+ @fields << Field.new(node['name'], node['value'] || '')
287
287
  end
288
288
  end
289
289
 
@@ -318,7 +318,7 @@ module WWW
318
318
  1.upto(len) { |i| string << chars[rand(chars.size-1)] }
319
319
  string
320
320
  end
321
-
321
+
322
322
  def mime_value_quote(str)
323
323
  str.gsub(/(["\r\\])/){|s| '\\' + s}
324
324
  end
@@ -328,7 +328,7 @@ module WWW
328
328
  "#{mime_value_quote(name)}\"\r\n" +
329
329
  "\r\n#{value}\r\n"
330
330
  end
331
-
331
+
332
332
  def file_to_multipart(file)
333
333
  file_name = file.file_name ? ::File.basename(file.file_name) : ''
334
334
  body = "Content-Disposition: form-data; name=\"" +
@@ -345,7 +345,7 @@ module WWW
345
345
  if file.mime_type != nil
346
346
  body << "Content-Type: #{file.mime_type}\r\n"
347
347
  end
348
-
348
+
349
349
  body <<
350
350
  if file.file_data.respond_to? :read
351
351
  "\r\n#{file.file_data.read}\r\n"
@@ -57,10 +57,15 @@ module WWW
57
57
  def encoding=(encoding)
58
58
  @encoding = encoding
59
59
 
60
- if @parser && @parser.encoding.downcase != encoding.downcase
61
- # lazy reinitialize the parser with the new encoding
62
- @parser = nil
60
+ if @parser
61
+ parser_encoding = @parser.encoding
62
+ if (parser_encoding && parser_encoding.downcase) != (encoding && encoding.downcase)
63
+ # lazy reinitialize the parser with the new encoding
64
+ @parser = nil
65
+ end
63
66
  end
67
+
68
+ encoding
64
69
  end
65
70
 
66
71
  def encoding
data/lib/www/mechanize.rb CHANGED
@@ -479,7 +479,7 @@ module WWW
479
479
  @keep_alive_time,
480
480
  @cookie_jar,
481
481
  @user_agent,
482
- {}
482
+ @request_headers
483
483
  ),
484
484
  Chain::CustomHeaders.new,
485
485
  @pre_connect_hook,
data/mechanize.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{mechanize}
5
- s.version = "0.9.3.20090617085936"
5
+ s.version = "0.9.3.20090623142847"
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{2009-06-17}
9
+ s.date = %q{2009-06-23}
10
10
  s.description = %q{The Mechanize library is used for automating interaction with websites.
11
11
  Mechanize automatically stores and sends cookies, follows redirects,
12
12
  can follow links, and submit forms. Form fields can be populated and
@@ -29,13 +29,13 @@ a history.}
29
29
 
30
30
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
31
31
  s.add_runtime_dependency(%q<nokogiri>, [">= 1.2.1"])
32
- s.add_development_dependency(%q<hoe>, [">= 2.1.0"])
32
+ s.add_development_dependency(%q<hoe>, [">= 2.2.0"])
33
33
  else
34
34
  s.add_dependency(%q<nokogiri>, [">= 1.2.1"])
35
- s.add_dependency(%q<hoe>, [">= 2.1.0"])
35
+ s.add_dependency(%q<hoe>, [">= 2.2.0"])
36
36
  end
37
37
  else
38
38
  s.add_dependency(%q<nokogiri>, [">= 1.2.1"])
39
- s.add_dependency(%q<hoe>, [">= 2.1.0"])
39
+ s.add_dependency(%q<hoe>, [">= 2.2.0"])
40
40
  end
41
41
  end
@@ -6,6 +6,14 @@ class TestFormAction < Test::Unit::TestCase
6
6
  @page = @agent.get("http://localhost/tc_form_action.html")
7
7
  end
8
8
 
9
+ def test_post_with_bad_encoding_does_not_raise_exception
10
+ @page = @agent.get("http://localhost/test_bad_encoding.html")
11
+ form = @page.form(:name => 'post_form1') { |f|
12
+ f.first_name = "Aaron"
13
+ }
14
+ form.submit
15
+ end
16
+
9
17
  def test_post_encoded_action
10
18
  form = @page.form(:name => 'post_form1') { |f|
11
19
  f.first_name = "Aaron"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tenderlove-mechanize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3.20090617085936
4
+ version: 0.9.3.20090623142847
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-06-17 00:00:00 -07:00
13
+ date: 2009-06-23 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -31,7 +31,7 @@ dependencies:
31
31
  requirements:
32
32
  - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: 2.1.0
34
+ version: 2.2.0
35
35
  version:
36
36
  description: 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.
37
37
  email: