mechanize 0.5.0 → 0.5.1

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.

data/CHANGELOG CHANGED
@@ -1,5 +1,10 @@
1
1
  = Mechanize CHANGELOG
2
2
 
3
+ == 0.5.1
4
+
5
+ * Fixed bug with file uploads
6
+ * Added performance tweaks to the cookie class
7
+
3
8
  == 0.5.0
4
9
 
5
10
  * Added pluggable parsers. (Thanks to Eric Kolve for the idea)
data/NOTES CHANGED
@@ -1,5 +1,11 @@
1
1
  = Mechanize Release Notes
2
2
 
3
+ == 0.5.1
4
+
5
+ This release is a small bugfix release. The main bug fixed in this release is
6
+ a problem with file uploading. I have also made some performance improvements
7
+ to cookie parsing.
8
+
3
9
  == 0.5.0
4
10
 
5
11
  Good News first:
@@ -13,76 +13,61 @@ module WWW
13
13
  @domain = cookie[:domain]
14
14
  @expires = cookie[:expires]
15
15
  @secure = cookie[:secure]
16
- @string = "#{cookie[:name]}=#{cookie[:value]}"
17
16
  end
18
17
 
19
18
  def Cookie::parse(uri, raw_cookie, &block)
20
19
  esc = raw_cookie.gsub(/(expires=[^,]*),([^;]*(;|$))/i) { "#{$1}#{$2}" }
21
20
  esc.split(/,/).each do |cookie_text|
22
- cookie_values = Hash.new
23
21
  cookie = Hash.new
22
+ valid_cookie = true
24
23
  cookie_text.split(/; ?/).each do |data|
25
24
  name, value = data.split('=', 2)
26
25
  next unless name
27
- cookie[name.strip] = value
28
- end
29
-
30
- cookie_values[:path] = cookie.delete(
31
- cookie.keys.find { |k| k.downcase == "path" } ) || uri.path
32
26
 
33
- expires_key = cookie.keys.find { |k| k.downcase == "expires" }
34
- if expires_key
35
- time = nil
36
- expires_val = cookie.delete(expires_key)
27
+ name.strip!
28
+
29
+ # Set the cookie to invalid if the domain is incorrect
30
+ case name.downcase
31
+ when 'path'
32
+ cookie[:path] = value
33
+ when 'expires'
34
+ cookie[:expires] = begin
35
+ Time::parse(value)
36
+ rescue
37
+ Time.now
38
+ end
39
+ when 'secure'
40
+ cookie[:secure] = true
41
+ when 'domain' # Reject the cookie if it isn't for this domain
42
+ cookie[:domain] = value.sub(/^\./, '')
37
43
 
38
- # If we can't parse the time, set it to the current time
39
- begin
40
- time = Time::parse(expires_val)
41
- rescue
42
- time = Time.now
44
+ # Reject cookies not for this domain
45
+ # TODO Move the logic to reject based on host to the jar
46
+ unless uri.host =~ /#{cookie[:domain]}$/
47
+ valid_cookie = false
48
+ end
49
+ when 'httponly'
50
+ # do nothing
51
+ # http://msdn.microsoft.com/workshop/author/dhtml/httponly_cookies.asp
52
+ else
53
+ cookie[:name] = name
54
+ cookie[:value] = value
43
55
  end
44
-
45
- # If we couldn't parse it, set it to the current time
46
- time = Time.now if time == nil
47
- cookie_values[:expires] = time
48
- end
49
-
50
- secure_key = cookie.keys.find { |k| k.downcase == "secure" }
51
- if secure_key
52
- cookie_values[:secure] = true
53
- cookie.delete(secure_key)
54
- else
55
- cookie_values[:secure] = false
56
56
  end
57
-
58
- # Set the domain name of the cookie
59
- domain_key = cookie.keys.find { |k| k.downcase == "domain" }
60
- if domain_key
61
- domain = cookie.delete(domain_key)
62
- domain.sub!(/^\./, '')
63
57
 
64
- # Reject cookies not for this domain
65
- next unless uri.host =~ /#{domain}$/
66
- cookie_values[:domain] = domain
67
- else
68
- cookie_values[:domain] = uri.host
69
- end
58
+ # Don't yield this cookie if it is invalid
59
+ next unless valid_cookie
70
60
 
71
- # Delete the http only option
72
- # http://msdn.microsoft.com/workshop/author/dhtml/httponly_cookies.asp
73
- http_only = cookie.keys.find { |k| k.downcase == 'httponly' }
74
- cookie.delete(http_only) if http_only
61
+ cookie[:path] ||= uri.path
62
+ cookie[:secure] ||= false
63
+ cookie[:domain] ||= uri.host
75
64
 
76
- cookie.each { |k,v|
77
- cookie_values[:name] = k.strip
78
- cookie_values[:value] = v.strip
79
- }
80
- yield Cookie.new(cookie_values)
65
+ yield Cookie.new(cookie)
81
66
  end
82
67
  end
83
68
 
84
69
  def to_s
85
- @string
70
+ "#{@name}=#{@value}"
86
71
  end
87
72
  end
88
73
 
@@ -110,7 +110,7 @@ module WWW
110
110
  case @enctype.downcase
111
111
  when 'multipart/form-data'
112
112
  boundary = rand_string(20)
113
- @enctype << ", boundary=#{boundary}"
113
+ @enctype << "; boundary=#{boundary}"
114
114
  params = []
115
115
  query_params.each { |k,v| params << param_to_multipart(k, v) }
116
116
  @file_uploads.each { |f| params << file_to_multipart(f) }
@@ -119,7 +119,7 @@ module WWW
119
119
  else
120
120
  query = WWW::Mechanize.build_query_string(query_params)
121
121
  end
122
-
122
+
123
123
  query
124
124
  end
125
125
 
@@ -180,7 +180,7 @@ module WWW
180
180
  def file_to_multipart(file)
181
181
  body = "Content-Disposition: form-data; name=\"" +
182
182
  "#{mime_value_quote(file.name)}\"; " +
183
- "filename=\"#{mime_value_quote(file.file_name)}\"\r\n" +
183
+ "filename=\"#{mime_value_quote(file.file_name || '')}\"\r\n" +
184
184
  "Content-Transfer-Encoding: binary\r\n"
185
185
  if file.mime_type != nil
186
186
  body << "Content-Type: #{file.mime_type}\r\n"
@@ -98,7 +98,7 @@ module WWW
98
98
  if n.name.downcase == 'option'
99
99
  option = Option.new(n)
100
100
  @options << option
101
- value = option.value if option.selected
101
+ value = option.value if option.selected && value.nil?
102
102
  end
103
103
  }
104
104
  value = @options.first.value if (value == nil && @options.first)
@@ -2,6 +2,6 @@
2
2
  # This file is auto-generated by build scripts
3
3
  module WWW
4
4
  class Mechanize
5
- Version = '0.5.0'
5
+ Version = '0.5.1'
6
6
  end
7
7
  end
data/test/tc_upload.rb CHANGED
@@ -52,4 +52,16 @@ class UploadMechTest < Test::Unit::TestCase
52
52
  page.body
53
53
  )
54
54
  end
55
+
56
+ def test_submit_no_file
57
+ page = @agent.get("http://localhost:#{PORT}/file_upload.html")
58
+ form = page.forms.first
59
+ form.fields.name('name').value = 'Aaron'
60
+ page = @agent.submit(form)
61
+ assert_match('Aaron', page.body)
62
+ assert_match(
63
+ "Content-Disposition: form-data; name=\"userfile1\"; filename=\"\"",
64
+ page.body
65
+ )
66
+ end
55
67
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: mechanize
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.5.0
7
- date: 2006-07-05 00:00:00 -07:00
6
+ version: 0.5.1
7
+ date: 2006-07-21 00:00:00 -07:00
8
8
  summary: Mechanize provides automated web-browsing
9
9
  require_paths:
10
10
  - lib
@@ -81,7 +81,6 @@ files:
81
81
  - lib/mechanize
82
82
  - lib/mechanize.rb
83
83
  - lib/mechanize/cookie.rb
84
- - lib/mechanize/cookie.rb.rej
85
84
  - lib/mechanize/errors.rb
86
85
  - lib/mechanize/form.rb
87
86
  - lib/mechanize/form_elements.rb
@@ -1,16 +0,0 @@
1
- ***************
2
- *** 140,145 ****
3
- def cookies(url)
4
- cleanup
5
- cookies = []
6
- @jar.each_key do |domain|
7
- if url.host =~ /#{domain}$/
8
- @jar[domain].each_key do |name|
9
- --- 140,146 ----
10
- def cookies(url)
11
- cleanup
12
- cookies = []
13
- + url.path = '/' if url.path.empty?
14
- @jar.each_key do |domain|
15
- if url.host =~ /#{domain}$/
16
- @jar[domain].each_key do |name|