addressable 2.2.3 → 2.7.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of addressable might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/CHANGELOG.md +235 -0
- data/Gemfile +32 -0
- data/LICENSE.txt +202 -0
- data/README.md +121 -0
- data/Rakefile +9 -17
- data/data/unicode.data +0 -0
- data/lib/addressable.rb +4 -0
- data/lib/addressable/idna.rb +26 -4870
- data/lib/addressable/idna/native.rb +61 -0
- data/lib/addressable/idna/pure.rb +676 -0
- data/lib/addressable/template.rb +581 -585
- data/lib/addressable/uri.rb +870 -609
- data/lib/addressable/version.rb +16 -20
- data/spec/addressable/idna_spec.rb +170 -64
- data/spec/addressable/net_http_compat_spec.rb +30 -0
- data/spec/addressable/rack_mount_compat_spec.rb +106 -0
- data/spec/addressable/security_spec.rb +59 -0
- data/spec/addressable/template_spec.rb +1346 -2047
- data/spec/addressable/uri_spec.rb +3472 -1198
- data/spec/spec_helper.rb +24 -0
- data/tasks/clobber.rake +2 -0
- data/tasks/gem.rake +28 -19
- data/tasks/git.rake +9 -2
- data/tasks/metrics.rake +2 -0
- data/tasks/rspec.rake +23 -0
- data/tasks/yard.rake +7 -4
- metadata +78 -117
- data/CHANGELOG +0 -101
- data/LICENSE +0 -20
- data/README +0 -60
- data/tasks/rdoc.rake +0 -26
- data/tasks/rubyforge.rake +0 -89
- data/tasks/spec.rake +0 -47
- data/website/index.html +0 -110
data/lib/addressable/version.rb
CHANGED
@@ -1,34 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# encoding:utf-8
|
2
4
|
#--
|
3
|
-
#
|
5
|
+
# Copyright (C) Bob Aman
|
4
6
|
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
# without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
# distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
# permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
# the following conditions:
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
12
10
|
#
|
13
|
-
#
|
14
|
-
# included in all copies or substantial portions of the Software.
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
15
12
|
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
23
18
|
#++
|
24
19
|
|
20
|
+
|
25
21
|
# Used to prevent the class/module from being loaded more than once
|
26
22
|
if !defined?(Addressable::VERSION)
|
27
23
|
module Addressable
|
28
|
-
module VERSION
|
24
|
+
module VERSION
|
29
25
|
MAJOR = 2
|
30
|
-
MINOR =
|
31
|
-
TINY =
|
26
|
+
MINOR = 7
|
27
|
+
TINY = 0
|
32
28
|
|
33
29
|
STRING = [MAJOR, MINOR, TINY].join('.')
|
34
30
|
end
|
@@ -1,59 +1,63 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# coding: utf-8
|
4
|
+
# Copyright (C) Bob Aman
|
4
5
|
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
# without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
# distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
# permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
# the following conditions:
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
12
9
|
#
|
13
|
-
#
|
14
|
-
# included in all copies or substantial portions of the Software.
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
15
11
|
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
|
22
|
-
|
23
|
-
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
|
18
|
+
|
19
|
+
require "spec_helper"
|
20
|
+
|
21
|
+
# Have to use RubyGems to load the idn gem.
|
22
|
+
require "rubygems"
|
24
23
|
|
25
24
|
require "addressable/idna"
|
26
25
|
|
27
|
-
|
26
|
+
shared_examples_for "converting from unicode to ASCII" do
|
28
27
|
it "should convert 'www.google.com' correctly" do
|
29
|
-
Addressable::IDNA.to_ascii("www.google.com").
|
28
|
+
expect(Addressable::IDNA.to_ascii("www.google.com")).to eq("www.google.com")
|
29
|
+
end
|
30
|
+
|
31
|
+
long = 'AcinusFallumTrompetumNullunCreditumVisumEstAtCuadLongumEtCefallum.com'
|
32
|
+
it "should convert '#{long}' correctly" do
|
33
|
+
expect(Addressable::IDNA.to_ascii(long)).to eq(long)
|
30
34
|
end
|
31
35
|
|
32
36
|
it "should convert 'www.詹姆斯.com' correctly" do
|
33
|
-
Addressable::IDNA.to_ascii(
|
37
|
+
expect(Addressable::IDNA.to_ascii(
|
34
38
|
"www.詹姆斯.com"
|
35
|
-
).
|
39
|
+
)).to eq("www.xn--8ws00zhy3a.com")
|
36
40
|
end
|
37
41
|
|
38
42
|
it "should convert 'www.Iñtërnâtiônàlizætiøn.com' correctly" do
|
39
43
|
"www.Iñtërnâtiônàlizætiøn.com"
|
40
|
-
Addressable::IDNA.to_ascii(
|
44
|
+
expect(Addressable::IDNA.to_ascii(
|
41
45
|
"www.I\xC3\xB1t\xC3\xABrn\xC3\xA2ti\xC3\xB4" +
|
42
46
|
"n\xC3\xA0liz\xC3\xA6ti\xC3\xB8n.com"
|
43
|
-
).
|
47
|
+
)).to eq("www.xn--itrntinliztin-vdb0a5exd8ewcye.com")
|
44
48
|
end
|
45
49
|
|
46
50
|
it "should convert 'www.Iñtërnâtiônàlizætiøn.com' correctly" do
|
47
|
-
Addressable::IDNA.to_ascii(
|
51
|
+
expect(Addressable::IDNA.to_ascii(
|
48
52
|
"www.In\xCC\x83te\xCC\x88rna\xCC\x82tio\xCC\x82n" +
|
49
53
|
"a\xCC\x80liz\xC3\xA6ti\xC3\xB8n.com"
|
50
|
-
).
|
54
|
+
)).to eq("www.xn--itrntinliztin-vdb0a5exd8ewcye.com")
|
51
55
|
end
|
52
56
|
|
53
57
|
it "should convert " +
|
54
58
|
"'www.ほんとうにながいわけのわからないどめいんめいのらべるまだながくしないとたりない.w3.mag.keio.ac.jp' " +
|
55
59
|
"correctly" do
|
56
|
-
Addressable::IDNA.to_ascii(
|
60
|
+
expect(Addressable::IDNA.to_ascii(
|
57
61
|
"www.\343\201\273\343\202\223\343\201\250\343\201\206\343\201\253\343" +
|
58
62
|
"\201\252\343\201\214\343\201\204\343\202\217\343\201\221\343\201\256" +
|
59
63
|
"\343\202\217\343\201\213\343\202\211\343\201\252\343\201\204\343\201" +
|
@@ -62,15 +66,16 @@ describe Addressable::IDNA, "when converting from unicode to ASCII" do
|
|
62
66
|
"\343\201\252\343\201\214\343\201\217\343\201\227\343\201\252\343\201" +
|
63
67
|
"\204\343\201\250\343\201\237\343\202\212\343\201\252\343\201\204." +
|
64
68
|
"w3.mag.keio.ac.jp"
|
65
|
-
).
|
69
|
+
)).to eq(
|
66
70
|
"www.xn--n8jaaaaai5bhf7as8fsfk3jnknefdde3" +
|
67
71
|
"fg11amb5gzdb4wi9bya3kc6lra.w3.mag.keio.ac.jp"
|
72
|
+
)
|
68
73
|
end
|
69
74
|
|
70
75
|
it "should convert " +
|
71
76
|
"'www.ほんとうにながいわけのわからないどめいんめいのらべるまだながくしないとたりない.w3.mag.keio.ac.jp' " +
|
72
77
|
"correctly" do
|
73
|
-
Addressable::IDNA.to_ascii(
|
78
|
+
expect(Addressable::IDNA.to_ascii(
|
74
79
|
"www.\343\201\273\343\202\223\343\201\250\343\201\206\343\201\253\343" +
|
75
80
|
"\201\252\343\201\213\343\202\231\343\201\204\343\202\217\343\201\221" +
|
76
81
|
"\343\201\256\343\202\217\343\201\213\343\202\211\343\201\252\343\201" +
|
@@ -80,115 +85,216 @@ describe Addressable::IDNA, "when converting from unicode to ASCII" do
|
|
80
85
|
"\213\343\202\231\343\201\217\343\201\227\343\201\252\343\201\204\343" +
|
81
86
|
"\201\250\343\201\237\343\202\212\343\201\252\343\201\204." +
|
82
87
|
"w3.mag.keio.ac.jp"
|
83
|
-
).
|
88
|
+
)).to eq(
|
84
89
|
"www.xn--n8jaaaaai5bhf7as8fsfk3jnknefdde3" +
|
85
90
|
"fg11amb5gzdb4wi9bya3kc6lra.w3.mag.keio.ac.jp"
|
91
|
+
)
|
86
92
|
end
|
87
93
|
|
88
94
|
it "should convert '点心和烤鸭.w3.mag.keio.ac.jp' correctly" do
|
89
|
-
Addressable::IDNA.to_ascii(
|
95
|
+
expect(Addressable::IDNA.to_ascii(
|
90
96
|
"点心和烤鸭.w3.mag.keio.ac.jp"
|
91
|
-
).
|
97
|
+
)).to eq("xn--0trv4xfvn8el34t.w3.mag.keio.ac.jp")
|
92
98
|
end
|
93
99
|
|
94
100
|
it "should convert '가각갂갃간갅갆갇갈갉힢힣.com' correctly" do
|
95
|
-
Addressable::IDNA.to_ascii(
|
101
|
+
expect(Addressable::IDNA.to_ascii(
|
96
102
|
"가각갂갃간갅갆갇갈갉힢힣.com"
|
97
|
-
).
|
103
|
+
)).to eq("xn--o39acdefghijk5883jma.com")
|
98
104
|
end
|
99
105
|
|
100
106
|
it "should convert " +
|
101
107
|
"'\347\242\274\346\250\231\346\272\226\350" +
|
102
108
|
"\220\254\345\234\213\347\242\274.com' correctly" do
|
103
|
-
Addressable::IDNA.to_ascii(
|
109
|
+
expect(Addressable::IDNA.to_ascii(
|
104
110
|
"\347\242\274\346\250\231\346\272\226\350" +
|
105
111
|
"\220\254\345\234\213\347\242\274.com"
|
106
|
-
).
|
112
|
+
)).to eq("xn--9cs565brid46mda086o.com")
|
107
113
|
end
|
108
114
|
|
109
115
|
it "should convert 'リ宠퐱〹.com' correctly" do
|
110
|
-
Addressable::IDNA.to_ascii(
|
116
|
+
expect(Addressable::IDNA.to_ascii(
|
111
117
|
"\357\276\230\345\256\240\355\220\261\343\200\271.com"
|
112
|
-
).
|
118
|
+
)).to eq("xn--eek174hoxfpr4k.com")
|
113
119
|
end
|
114
120
|
|
115
121
|
it "should convert 'リ宠퐱卄.com' correctly" do
|
116
|
-
Addressable::IDNA.to_ascii(
|
122
|
+
expect(Addressable::IDNA.to_ascii(
|
117
123
|
"\343\203\252\345\256\240\355\220\261\345\215\204.com"
|
118
|
-
).
|
124
|
+
)).to eq("xn--eek174hoxfpr4k.com")
|
119
125
|
end
|
120
126
|
|
121
127
|
it "should convert 'ᆵ' correctly" do
|
122
|
-
Addressable::IDNA.to_ascii(
|
128
|
+
expect(Addressable::IDNA.to_ascii(
|
123
129
|
"\341\206\265"
|
124
|
-
).
|
130
|
+
)).to eq("xn--4ud")
|
125
131
|
end
|
126
132
|
|
127
133
|
it "should convert 'ᆵ' correctly" do
|
128
|
-
Addressable::IDNA.to_ascii(
|
134
|
+
expect(Addressable::IDNA.to_ascii(
|
129
135
|
"\357\276\257"
|
130
|
-
).
|
136
|
+
)).to eq("xn--4ud")
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should convert '🌹🌹🌹.ws' correctly" do
|
140
|
+
expect(Addressable::IDNA.to_ascii(
|
141
|
+
"\360\237\214\271\360\237\214\271\360\237\214\271.ws"
|
142
|
+
)).to eq("xn--2h8haa.ws")
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should handle two adjacent '.'s correctly" do
|
146
|
+
expect(Addressable::IDNA.to_ascii(
|
147
|
+
"example..host"
|
148
|
+
)).to eq("example..host")
|
131
149
|
end
|
132
150
|
end
|
133
151
|
|
134
|
-
|
152
|
+
shared_examples_for "converting from ASCII to unicode" do
|
153
|
+
long = 'AcinusFallumTrompetumNullunCreditumVisumEstAtCuadLongumEtCefallum.com'
|
154
|
+
it "should convert '#{long}' correctly" do
|
155
|
+
expect(Addressable::IDNA.to_unicode(long)).to eq(long)
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should return the identity conversion when punycode decode fails" do
|
159
|
+
expect(Addressable::IDNA.to_unicode("xn--zckp1cyg1.sblo.jp")).to eq(
|
160
|
+
"xn--zckp1cyg1.sblo.jp")
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should return the identity conversion when the ACE prefix has no suffix" do
|
164
|
+
expect(Addressable::IDNA.to_unicode("xn--...-")).to eq("xn--...-")
|
165
|
+
end
|
166
|
+
|
135
167
|
it "should convert 'www.google.com' correctly" do
|
136
|
-
Addressable::IDNA.to_unicode("www.google.com").
|
168
|
+
expect(Addressable::IDNA.to_unicode("www.google.com")).to eq(
|
169
|
+
"www.google.com")
|
137
170
|
end
|
138
171
|
|
139
172
|
it "should convert 'www.詹姆斯.com' correctly" do
|
140
|
-
Addressable::IDNA.to_unicode(
|
173
|
+
expect(Addressable::IDNA.to_unicode(
|
141
174
|
"www.xn--8ws00zhy3a.com"
|
142
|
-
).
|
175
|
+
)).to eq("www.詹姆斯.com")
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should convert '詹姆斯.com' correctly" do
|
179
|
+
expect(Addressable::IDNA.to_unicode(
|
180
|
+
"xn--8ws00zhy3a.com"
|
181
|
+
)).to eq("詹姆斯.com")
|
143
182
|
end
|
144
183
|
|
145
184
|
it "should convert 'www.iñtërnâtiônàlizætiøn.com' correctly" do
|
146
|
-
Addressable::IDNA.to_unicode(
|
185
|
+
expect(Addressable::IDNA.to_unicode(
|
147
186
|
"www.xn--itrntinliztin-vdb0a5exd8ewcye.com"
|
148
|
-
).
|
187
|
+
)).to eq("www.iñtërnâtiônàlizætiøn.com")
|
188
|
+
end
|
189
|
+
|
190
|
+
it "should convert 'iñtërnâtiônàlizætiøn.com' correctly" do
|
191
|
+
expect(Addressable::IDNA.to_unicode(
|
192
|
+
"xn--itrntinliztin-vdb0a5exd8ewcye.com"
|
193
|
+
)).to eq("iñtërnâtiônàlizætiøn.com")
|
149
194
|
end
|
150
195
|
|
151
196
|
it "should convert " +
|
152
197
|
"'www.ほんとうにながいわけのわからないどめいんめいのらべるまだながくしないとたりない.w3.mag.keio.ac.jp' " +
|
153
198
|
"correctly" do
|
154
|
-
Addressable::IDNA.to_unicode(
|
199
|
+
expect(Addressable::IDNA.to_unicode(
|
155
200
|
"www.xn--n8jaaaaai5bhf7as8fsfk3jnknefdde3" +
|
156
201
|
"fg11amb5gzdb4wi9bya3kc6lra.w3.mag.keio.ac.jp"
|
157
|
-
).
|
202
|
+
)).to eq(
|
158
203
|
"www.ほんとうにながいわけのわからないどめいんめいのらべるまだながくしないとたりない.w3.mag.keio.ac.jp"
|
204
|
+
)
|
159
205
|
end
|
160
206
|
|
161
207
|
it "should convert '点心和烤鸭.w3.mag.keio.ac.jp' correctly" do
|
162
|
-
Addressable::IDNA.to_unicode(
|
208
|
+
expect(Addressable::IDNA.to_unicode(
|
163
209
|
"xn--0trv4xfvn8el34t.w3.mag.keio.ac.jp"
|
164
|
-
).
|
210
|
+
)).to eq("点心和烤鸭.w3.mag.keio.ac.jp")
|
165
211
|
end
|
166
212
|
|
167
213
|
it "should convert '가각갂갃간갅갆갇갈갉힢힣.com' correctly" do
|
168
|
-
Addressable::IDNA.to_unicode(
|
214
|
+
expect(Addressable::IDNA.to_unicode(
|
169
215
|
"xn--o39acdefghijk5883jma.com"
|
170
|
-
).
|
216
|
+
)).to eq("가각갂갃간갅갆갇갈갉힢힣.com")
|
171
217
|
end
|
172
218
|
|
173
219
|
it "should convert " +
|
174
220
|
"'\347\242\274\346\250\231\346\272\226\350" +
|
175
221
|
"\220\254\345\234\213\347\242\274.com' correctly" do
|
176
|
-
Addressable::IDNA.to_unicode(
|
222
|
+
expect(Addressable::IDNA.to_unicode(
|
177
223
|
"xn--9cs565brid46mda086o.com"
|
178
|
-
).
|
224
|
+
)).to eq(
|
179
225
|
"\347\242\274\346\250\231\346\272\226\350" +
|
180
226
|
"\220\254\345\234\213\347\242\274.com"
|
227
|
+
)
|
181
228
|
end
|
182
229
|
|
183
230
|
it "should convert 'リ宠퐱卄.com' correctly" do
|
184
|
-
Addressable::IDNA.to_unicode(
|
231
|
+
expect(Addressable::IDNA.to_unicode(
|
185
232
|
"xn--eek174hoxfpr4k.com"
|
186
|
-
).
|
233
|
+
)).to eq("\343\203\252\345\256\240\355\220\261\345\215\204.com")
|
187
234
|
end
|
188
235
|
|
189
236
|
it "should convert 'ᆵ' correctly" do
|
190
|
-
Addressable::IDNA.to_unicode(
|
237
|
+
expect(Addressable::IDNA.to_unicode(
|
191
238
|
"xn--4ud"
|
192
|
-
).
|
239
|
+
)).to eq("\341\206\265")
|
240
|
+
end
|
241
|
+
|
242
|
+
it "should convert '🌹🌹🌹.ws' correctly" do
|
243
|
+
expect(Addressable::IDNA.to_unicode(
|
244
|
+
"xn--2h8haa.ws"
|
245
|
+
)).to eq("\360\237\214\271\360\237\214\271\360\237\214\271.ws")
|
246
|
+
end
|
247
|
+
|
248
|
+
it "should handle two adjacent '.'s correctly" do
|
249
|
+
expect(Addressable::IDNA.to_unicode(
|
250
|
+
"example..host"
|
251
|
+
)).to eq("example..host")
|
252
|
+
end
|
253
|
+
|
254
|
+
it "should normalize 'string' correctly" do
|
255
|
+
expect(Addressable::IDNA.unicode_normalize_kc(:'string')).to eq("string")
|
256
|
+
expect(Addressable::IDNA.unicode_normalize_kc("string")).to eq("string")
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
describe Addressable::IDNA, "when using the pure-Ruby implementation" do
|
261
|
+
before do
|
262
|
+
Addressable.send(:remove_const, :IDNA)
|
263
|
+
load "addressable/idna/pure.rb"
|
264
|
+
end
|
265
|
+
|
266
|
+
it_should_behave_like "converting from unicode to ASCII"
|
267
|
+
it_should_behave_like "converting from ASCII to unicode"
|
268
|
+
|
269
|
+
begin
|
270
|
+
require "fiber"
|
271
|
+
|
272
|
+
it "should not blow up inside fibers" do
|
273
|
+
f = Fiber.new do
|
274
|
+
Addressable.send(:remove_const, :IDNA)
|
275
|
+
load "addressable/idna/pure.rb"
|
276
|
+
end
|
277
|
+
f.resume
|
278
|
+
end
|
279
|
+
rescue LoadError
|
280
|
+
# Fibers aren't supported in this version of Ruby, skip this test.
|
281
|
+
warn('Fibers unsupported.')
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
begin
|
286
|
+
require "idn"
|
287
|
+
|
288
|
+
describe Addressable::IDNA, "when using the native-code implementation" do
|
289
|
+
before do
|
290
|
+
Addressable.send(:remove_const, :IDNA)
|
291
|
+
load "addressable/idna/native.rb"
|
292
|
+
end
|
293
|
+
|
294
|
+
it_should_behave_like "converting from unicode to ASCII"
|
295
|
+
it_should_behave_like "converting from ASCII to unicode"
|
193
296
|
end
|
297
|
+
rescue LoadError
|
298
|
+
# Cannot test the native implementation without libidn support.
|
299
|
+
warn('Could not load native IDN implementation.')
|
194
300
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# coding: utf-8
|
4
|
+
# Copyright (C) Bob Aman
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
|
18
|
+
|
19
|
+
require "spec_helper"
|
20
|
+
|
21
|
+
require "addressable/uri"
|
22
|
+
require "net/http"
|
23
|
+
|
24
|
+
describe Net::HTTP do
|
25
|
+
it "should be compatible with Addressable" do
|
26
|
+
response_body =
|
27
|
+
Net::HTTP.get(Addressable::URI.parse('http://www.google.com/'))
|
28
|
+
expect(response_body).not_to be_nil
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# coding: utf-8
|
4
|
+
# Copyright (C) Bob Aman
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
|
18
|
+
|
19
|
+
require "spec_helper"
|
20
|
+
|
21
|
+
require "addressable/uri"
|
22
|
+
require "addressable/template"
|
23
|
+
require "rack/mount"
|
24
|
+
|
25
|
+
describe Rack::Mount do
|
26
|
+
let(:app_one) do
|
27
|
+
proc { |env| [200, {'Content-Type' => 'text/plain'}, 'Route 1'] }
|
28
|
+
end
|
29
|
+
let(:app_two) do
|
30
|
+
proc { |env| [200, {'Content-Type' => 'text/plain'}, 'Route 2'] }
|
31
|
+
end
|
32
|
+
let(:app_three) do
|
33
|
+
proc { |env| [200, {'Content-Type' => 'text/plain'}, 'Route 3'] }
|
34
|
+
end
|
35
|
+
let(:routes) do
|
36
|
+
s = Rack::Mount::RouteSet.new do |set|
|
37
|
+
set.add_route(app_one, {
|
38
|
+
:request_method => 'GET',
|
39
|
+
:path_info => Addressable::Template.new('/one/{id}/')
|
40
|
+
}, {:id => 'unidentified'}, :one)
|
41
|
+
set.add_route(app_two, {
|
42
|
+
:request_method => 'GET',
|
43
|
+
:path_info => Addressable::Template.new('/two/')
|
44
|
+
}, {:id => 'unidentified'}, :two)
|
45
|
+
set.add_route(app_three, {
|
46
|
+
:request_method => 'GET',
|
47
|
+
:path_info => Addressable::Template.new('/three/{id}/').to_regexp
|
48
|
+
}, {:id => 'unidentified'}, :three)
|
49
|
+
end
|
50
|
+
s.rehash
|
51
|
+
s
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should generate from routes with Addressable::Template" do
|
55
|
+
path, _ = routes.generate(:path_info, :one, {:id => '123'})
|
56
|
+
expect(path).to eq '/one/123/'
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should generate from routes with Addressable::Template using defaults" do
|
60
|
+
path, _ = routes.generate(:path_info, :one, {})
|
61
|
+
expect(path).to eq '/one/unidentified/'
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should recognize routes with Addressable::Template" do
|
65
|
+
request = Rack::Request.new(
|
66
|
+
'REQUEST_METHOD' => 'GET',
|
67
|
+
'PATH_INFO' => '/one/123/'
|
68
|
+
)
|
69
|
+
route, _, params = routes.recognize(request)
|
70
|
+
expect(route).not_to be_nil
|
71
|
+
expect(route.app).to eq app_one
|
72
|
+
expect(params).to eq({id: '123'})
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should generate from routes with Addressable::Template" do
|
76
|
+
path, _ = routes.generate(:path_info, :two, {:id => '654'})
|
77
|
+
expect(path).to eq '/two/'
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should generate from routes with Addressable::Template using defaults" do
|
81
|
+
path, _ = routes.generate(:path_info, :two, {})
|
82
|
+
expect(path).to eq '/two/'
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should recognize routes with Addressable::Template" do
|
86
|
+
request = Rack::Request.new(
|
87
|
+
'REQUEST_METHOD' => 'GET',
|
88
|
+
'PATH_INFO' => '/two/'
|
89
|
+
)
|
90
|
+
route, _, params = routes.recognize(request)
|
91
|
+
expect(route).not_to be_nil
|
92
|
+
expect(route.app).to eq app_two
|
93
|
+
expect(params).to eq({id: 'unidentified'})
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should recognize routes with derived Regexp" do
|
97
|
+
request = Rack::Request.new(
|
98
|
+
'REQUEST_METHOD' => 'GET',
|
99
|
+
'PATH_INFO' => '/three/789/'
|
100
|
+
)
|
101
|
+
route, _, params = routes.recognize(request)
|
102
|
+
expect(route).not_to be_nil
|
103
|
+
expect(route.app).to eq app_three
|
104
|
+
expect(params).to eq({id: '789'})
|
105
|
+
end
|
106
|
+
end
|