1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
require 'test/unit'
require 'uri/mailto'
module URI
class TestMailTo < Test::Unit::TestCase
def setup
@u = URI::MailTo
end
def teardown
end
def uri_to_ary(uri)
uri.class.component.collect {|c| uri.send(c)}
end
def test_build
ok = []
bad = []
# RFC2368, 6. Examples
# mailto:[email protected]
ok << ["mailto:[email protected]"]
ok[-1] << ["[email protected]", nil]
ok[-1] << {:to => "[email protected]"}
# mailto:[email protected]?subject=current-issue
ok << ["mailto:[email protected]?subject=current-issue"]
ok[-1] << ["[email protected]", ["subject=current-issue"]]
ok[-1] << {:to => "[email protected]",
:headers => ["subject=current-issue"]}
# mailto:[email protected]?body=send%20current-issue
ok << ["mailto:[email protected]?body=send%20current-issue"]
ok[-1] << ["[email protected]", ["body=send%20current-issue"]]
ok[-1] << {:to => "[email protected]",
:headers => ["body=send%20current-issue"]}
# mailto:[email protected]?body=send%20current-issue%0D%0Asend%20index
ok << ["mailto:[email protected]?body=send%20current-issue%0D%0Asend%20index"]
ok[-1] << ["[email protected]",
["body=send%20current-issue%0D%0Asend%20index"]]
ok[-1] << {:to => "[email protected]",
:headers => ["body=send%20current-issue%0D%0Asend%20index"]}
# mailto:[email protected]?In-Reply-To=%[email protected]
ok << ["mailto:[email protected]?In-Reply-To=%[email protected]"]
ok[-1] << ["[email protected]",
["In-Reply-To=%[email protected]"]]
ok[-1] << {:to => "[email protected]",
:headers => ["In-Reply-To=%[email protected]"]}
# mailto:[email protected]?body=subscribe%20bamboo-l
ok << ["mailto:[email protected]?body=subscribe%20bamboo-l"]
ok[-1] << ["[email protected]", ["body=subscribe%20bamboo-l"]]
ok[-1] << {:to => "[email protected]",
:headers => ["body=subscribe%20bamboo-l"]}
# mailto:[email protected][email protected]&body=hello
ok << ["mailto:[email protected][email protected]&body=hello"]
ok[-1] << ["[email protected]", ["[email protected]", "body=hello"]]
ok[-1] << {:to => "[email protected]",
:headers => ["[email protected]", "body=hello"]}
# mailto:[email protected]&[email protected]&body=hello
ok << ["mailto:[email protected]&[email protected]&body=hello"]
ok[-1] << [nil,
["[email protected]", "[email protected]", "body=hello"]]
ok[-1] << {:headers => ["[email protected]",
"[email protected]", "body=hello"]}
# mailto:gorby%[email protected]
ok << ["mailto:gorby%[email protected]"]
ok[-1] << ["gorby%[email protected]", nil]
ok[-1] << {:to => "gorby%[email protected]"}
# mailto:unlikely%[email protected]?blat=foop
ok << ["mailto:unlikely%[email protected]?blat=foop"]
ok[-1] << ["unlikely%[email protected]", ["blat=foop"]]
ok[-1] << {:to => "unlikely%[email protected]",
:headers => ["blat=foop"]}
ok_all = ok.flatten.join("\0")
# mailto:[email protected][email protected]?body=hello ; WRONG!
bad << ["[email protected]", ["[email protected]?body=hello"]]
# mailto:javascript:alert()
bad << ["javascript:alert()", []]
# '=' which is in hname or hvalue is wrong.
bad << ["[email protected]?subject=1+1=2", []]
ok.each do |x|
assert_equal(x[0],
@u.build(x[1]).to_s)
assert_equal(x[0],
@u.build(x[2]).to_s)
end
bad.each do |x|
assert_raises(URI::InvalidComponentError) {
@u.build(x)
}
end
assert_equal(ok_all, ok.flatten.join("\0"))
end
def test_select
u = URI.parse('mailto:[email protected][email protected]&body=hello')
assert_equal(uri_to_ary(u), u.select(*u.component))
assert_raises(ArgumentError) do
u.select(:scheme, :host, :not_exist, :port)
end
end
end
end
|