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 +5 -0
- data/NOTES +6 -0
- data/lib/mechanize/cookie.rb +35 -50
- data/lib/mechanize/form.rb +3 -3
- data/lib/mechanize/form_elements.rb +1 -1
- data/lib/mechanize/mech_version.rb +1 -1
- data/test/tc_upload.rb +12 -0
- metadata +2 -3
- data/lib/mechanize/cookie.rb.rej +0 -16
data/CHANGELOG
CHANGED
data/NOTES
CHANGED
data/lib/mechanize/cookie.rb
CHANGED
@@ -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
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
-
|
65
|
-
|
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
|
-
|
72
|
-
|
73
|
-
|
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
|
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
|
-
@
|
70
|
+
"#{@name}=#{@value}"
|
86
71
|
end
|
87
72
|
end
|
88
73
|
|
data/lib/mechanize/form.rb
CHANGED
@@ -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 << "
|
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)
|
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.
|
7
|
-
date: 2006-07-
|
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
|
data/lib/mechanize/cookie.rb.rej
DELETED
@@ -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|
|