addressable 2.5.1 → 2.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CHANGELOG.md +36 -0
- data/Gemfile +13 -17
- data/README.md +14 -14
- data/Rakefile +5 -3
- data/addressable.gemspec +37 -0
- data/lib/addressable/idna/native.rb +4 -2
- data/lib/addressable/idna/pure.rb +54 -53
- data/lib/addressable/idna.rb +2 -0
- data/lib/addressable/template.rb +42 -76
- data/lib/addressable/uri.rb +128 -64
- data/lib/addressable/version.rb +4 -2
- data/lib/addressable.rb +2 -0
- data/spec/addressable/idna_spec.rb +23 -7
- data/spec/addressable/net_http_compat_spec.rb +2 -0
- data/spec/addressable/security_spec.rb +2 -0
- data/spec/addressable/template_spec.rb +42 -1
- data/spec/addressable/uri_spec.rb +408 -207
- data/spec/spec_helper.rb +12 -0
- data/tasks/clobber.rake +2 -0
- data/tasks/gem.rake +8 -7
- data/tasks/git.rake +2 -0
- data/tasks/metrics.rake +2 -0
- data/tasks/profile.rake +72 -0
- data/tasks/rspec.rake +3 -1
- data/tasks/yard.rake +2 -0
- metadata +22 -16
- data/spec/addressable/rack_mount_compat_spec.rb +0 -104
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# coding: utf-8
|
2
4
|
# Copyright (C) Bob Aman
|
3
5
|
#
|
@@ -63,116 +65,116 @@ end
|
|
63
65
|
|
64
66
|
describe Addressable::URI, "when created with a non-numeric port number" do
|
65
67
|
it "should raise an error" do
|
66
|
-
expect
|
68
|
+
expect do
|
67
69
|
Addressable::URI.new(:port => "bogus")
|
68
|
-
end
|
70
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
69
71
|
end
|
70
72
|
end
|
71
73
|
|
72
74
|
describe Addressable::URI, "when created with a invalid encoded port number" do
|
73
75
|
it "should raise an error" do
|
74
|
-
expect
|
76
|
+
expect do
|
75
77
|
Addressable::URI.new(:port => "%eb")
|
76
|
-
end
|
78
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
77
79
|
end
|
78
80
|
end
|
79
81
|
|
80
82
|
describe Addressable::URI, "when created with a non-string scheme" do
|
81
83
|
it "should raise an error" do
|
82
|
-
expect
|
84
|
+
expect do
|
83
85
|
Addressable::URI.new(:scheme => :bogus)
|
84
|
-
end
|
86
|
+
end.to raise_error(TypeError)
|
85
87
|
end
|
86
88
|
end
|
87
89
|
|
88
90
|
describe Addressable::URI, "when created with a non-string user" do
|
89
91
|
it "should raise an error" do
|
90
|
-
expect
|
92
|
+
expect do
|
91
93
|
Addressable::URI.new(:user => :bogus)
|
92
|
-
end
|
94
|
+
end.to raise_error(TypeError)
|
93
95
|
end
|
94
96
|
end
|
95
97
|
|
96
98
|
describe Addressable::URI, "when created with a non-string password" do
|
97
99
|
it "should raise an error" do
|
98
|
-
expect
|
100
|
+
expect do
|
99
101
|
Addressable::URI.new(:password => :bogus)
|
100
|
-
end
|
102
|
+
end.to raise_error(TypeError)
|
101
103
|
end
|
102
104
|
end
|
103
105
|
|
104
106
|
describe Addressable::URI, "when created with a non-string userinfo" do
|
105
107
|
it "should raise an error" do
|
106
|
-
expect
|
108
|
+
expect do
|
107
109
|
Addressable::URI.new(:userinfo => :bogus)
|
108
|
-
end
|
110
|
+
end.to raise_error(TypeError)
|
109
111
|
end
|
110
112
|
end
|
111
113
|
|
112
114
|
describe Addressable::URI, "when created with a non-string host" do
|
113
115
|
it "should raise an error" do
|
114
|
-
expect
|
116
|
+
expect do
|
115
117
|
Addressable::URI.new(:host => :bogus)
|
116
|
-
end
|
118
|
+
end.to raise_error(TypeError)
|
117
119
|
end
|
118
120
|
end
|
119
121
|
|
120
122
|
describe Addressable::URI, "when created with a non-string authority" do
|
121
123
|
it "should raise an error" do
|
122
|
-
expect
|
124
|
+
expect do
|
123
125
|
Addressable::URI.new(:authority => :bogus)
|
124
|
-
end
|
126
|
+
end.to raise_error(TypeError)
|
125
127
|
end
|
126
128
|
end
|
127
129
|
|
128
130
|
describe Addressable::URI, "when created with a non-string path" do
|
129
131
|
it "should raise an error" do
|
130
|
-
expect
|
132
|
+
expect do
|
131
133
|
Addressable::URI.new(:path => :bogus)
|
132
|
-
end
|
134
|
+
end.to raise_error(TypeError)
|
133
135
|
end
|
134
136
|
end
|
135
137
|
|
136
138
|
describe Addressable::URI, "when created with a non-string query" do
|
137
139
|
it "should raise an error" do
|
138
|
-
expect
|
140
|
+
expect do
|
139
141
|
Addressable::URI.new(:query => :bogus)
|
140
|
-
end
|
142
|
+
end.to raise_error(TypeError)
|
141
143
|
end
|
142
144
|
end
|
143
145
|
|
144
146
|
describe Addressable::URI, "when created with a non-string fragment" do
|
145
147
|
it "should raise an error" do
|
146
|
-
expect
|
148
|
+
expect do
|
147
149
|
Addressable::URI.new(:fragment => :bogus)
|
148
|
-
end
|
150
|
+
end.to raise_error(TypeError)
|
149
151
|
end
|
150
152
|
end
|
151
153
|
|
152
154
|
describe Addressable::URI, "when created with a scheme but no hierarchical " +
|
153
155
|
"segment" do
|
154
156
|
it "should raise an error" do
|
155
|
-
expect
|
157
|
+
expect do
|
156
158
|
Addressable::URI.parse("http:")
|
157
|
-
end
|
159
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
158
160
|
end
|
159
161
|
end
|
160
162
|
|
161
163
|
describe Addressable::URI, "quote handling" do
|
162
164
|
describe 'in host name' do
|
163
165
|
it "should raise an error for single quote" do
|
164
|
-
expect
|
166
|
+
expect do
|
165
167
|
Addressable::URI.parse("http://local\"host/")
|
166
|
-
end
|
168
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
167
169
|
end
|
168
170
|
end
|
169
171
|
end
|
170
172
|
|
171
173
|
describe Addressable::URI, "newline normalization" do
|
172
174
|
it "should not accept newlines in scheme" do
|
173
|
-
expect
|
175
|
+
expect do
|
174
176
|
Addressable::URI.parse("ht%0atp://localhost/")
|
175
|
-
end
|
177
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
176
178
|
end
|
177
179
|
|
178
180
|
it "should not unescape newline in path" do
|
@@ -197,47 +199,47 @@ describe Addressable::URI, "newline normalization" do
|
|
197
199
|
|
198
200
|
it "should not accept newline in hostname" do
|
199
201
|
uri = Addressable::URI.parse("http://localhost/")
|
200
|
-
expect
|
202
|
+
expect do
|
201
203
|
uri.host = "local\nhost"
|
202
|
-
end
|
204
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
203
205
|
end
|
204
206
|
end
|
205
207
|
|
206
208
|
describe Addressable::URI, "when created with ambiguous path" do
|
207
209
|
it "should raise an error" do
|
208
|
-
expect
|
210
|
+
expect do
|
209
211
|
Addressable::URI.parse("::http")
|
210
|
-
end
|
212
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
211
213
|
end
|
212
214
|
end
|
213
215
|
|
214
216
|
describe Addressable::URI, "when created with an invalid host" do
|
215
217
|
it "should raise an error" do
|
216
|
-
expect
|
218
|
+
expect do
|
217
219
|
Addressable::URI.new(:host => "<invalid>")
|
218
|
-
end
|
220
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
219
221
|
end
|
220
222
|
end
|
221
223
|
|
222
224
|
describe Addressable::URI, "when created with a host consisting of " +
|
223
225
|
"sub-delims characters" do
|
224
226
|
it "should not raise an error" do
|
225
|
-
expect
|
227
|
+
expect do
|
226
228
|
Addressable::URI.new(
|
227
229
|
:host => Addressable::URI::CharacterClasses::SUB_DELIMS.gsub(/\\/, '')
|
228
230
|
)
|
229
|
-
end
|
231
|
+
end.not_to raise_error
|
230
232
|
end
|
231
233
|
end
|
232
234
|
|
233
235
|
describe Addressable::URI, "when created with a host consisting of " +
|
234
236
|
"unreserved characters" do
|
235
237
|
it "should not raise an error" do
|
236
|
-
expect
|
238
|
+
expect do
|
237
239
|
Addressable::URI.new(
|
238
240
|
:host => Addressable::URI::CharacterClasses::UNRESERVED.gsub(/\\/, '')
|
239
241
|
)
|
240
|
-
end
|
242
|
+
end.not_to raise_error
|
241
243
|
end
|
242
244
|
end
|
243
245
|
|
@@ -267,83 +269,83 @@ describe Addressable::URI, "when created from nil components" do
|
|
267
269
|
end
|
268
270
|
|
269
271
|
it "should raise an error if the scheme is set to whitespace" do
|
270
|
-
expect
|
272
|
+
expect do
|
271
273
|
@uri.scheme = "\t \n"
|
272
|
-
end
|
274
|
+
end.to raise_error(Addressable::URI::InvalidURIError, /'\t \n'/)
|
273
275
|
end
|
274
276
|
|
275
277
|
it "should raise an error if the scheme is set to all digits" do
|
276
|
-
expect
|
278
|
+
expect do
|
277
279
|
@uri.scheme = "123"
|
278
|
-
end
|
280
|
+
end.to raise_error(Addressable::URI::InvalidURIError, /'123'/)
|
279
281
|
end
|
280
282
|
|
281
283
|
it "should raise an error if the scheme begins with a digit" do
|
282
|
-
expect
|
284
|
+
expect do
|
283
285
|
@uri.scheme = "1scheme"
|
284
|
-
end
|
286
|
+
end.to raise_error(Addressable::URI::InvalidURIError, /'1scheme'/)
|
285
287
|
end
|
286
288
|
|
287
289
|
it "should raise an error if the scheme begins with a plus" do
|
288
|
-
expect
|
290
|
+
expect do
|
289
291
|
@uri.scheme = "+scheme"
|
290
|
-
end
|
292
|
+
end.to raise_error(Addressable::URI::InvalidURIError, /'\+scheme'/)
|
291
293
|
end
|
292
294
|
|
293
295
|
it "should raise an error if the scheme begins with a dot" do
|
294
|
-
expect
|
296
|
+
expect do
|
295
297
|
@uri.scheme = ".scheme"
|
296
|
-
end
|
298
|
+
end.to raise_error(Addressable::URI::InvalidURIError, /'\.scheme'/)
|
297
299
|
end
|
298
300
|
|
299
301
|
it "should raise an error if the scheme begins with a dash" do
|
300
|
-
expect
|
302
|
+
expect do
|
301
303
|
@uri.scheme = "-scheme"
|
302
|
-
end
|
304
|
+
end.to raise_error(Addressable::URI::InvalidURIError, /'-scheme'/)
|
303
305
|
end
|
304
306
|
|
305
307
|
it "should raise an error if the scheme contains an illegal character" do
|
306
|
-
expect
|
308
|
+
expect do
|
307
309
|
@uri.scheme = "scheme!"
|
308
|
-
end
|
310
|
+
end.to raise_error(Addressable::URI::InvalidURIError, /'scheme!'/)
|
309
311
|
end
|
310
312
|
|
311
313
|
it "should raise an error if the scheme contains whitespace" do
|
312
|
-
expect
|
314
|
+
expect do
|
313
315
|
@uri.scheme = "sch eme"
|
314
|
-
end
|
316
|
+
end.to raise_error(Addressable::URI::InvalidURIError, /'sch eme'/)
|
315
317
|
end
|
316
318
|
|
317
319
|
it "should raise an error if the scheme contains a newline" do
|
318
|
-
expect
|
320
|
+
expect do
|
319
321
|
@uri.scheme = "sch\neme"
|
320
|
-
end
|
322
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
321
323
|
end
|
322
324
|
|
323
325
|
it "should raise an error if set into an invalid state" do
|
324
|
-
expect
|
326
|
+
expect do
|
325
327
|
@uri.user = "user"
|
326
|
-
end
|
328
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
327
329
|
end
|
328
330
|
|
329
331
|
it "should raise an error if set into an invalid state" do
|
330
|
-
expect
|
332
|
+
expect do
|
331
333
|
@uri.password = "pass"
|
332
|
-
end
|
334
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
333
335
|
end
|
334
336
|
|
335
337
|
it "should raise an error if set into an invalid state" do
|
336
|
-
expect
|
338
|
+
expect do
|
337
339
|
@uri.scheme = "http"
|
338
340
|
@uri.fragment = "fragment"
|
339
|
-
end
|
341
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
340
342
|
end
|
341
343
|
|
342
344
|
it "should raise an error if set into an invalid state" do
|
343
|
-
expect
|
345
|
+
expect do
|
344
346
|
@uri.fragment = "fragment"
|
345
347
|
@uri.scheme = "http"
|
346
|
-
end
|
348
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
347
349
|
end
|
348
350
|
end
|
349
351
|
|
@@ -955,6 +957,10 @@ describe Addressable::URI, "when frozen" do
|
|
955
957
|
expect(@uri.normalize.query).to eq("a=1")
|
956
958
|
end
|
957
959
|
|
960
|
+
it "returns '/%70a%74%68?a=%31' for #request_uri" do
|
961
|
+
expect(@uri.request_uri).to eq("/%70a%74%68?a=%31")
|
962
|
+
end
|
963
|
+
|
958
964
|
it "returns '1%323' for #fragment" do
|
959
965
|
expect(@uri.fragment).to eq("1%323")
|
960
966
|
end
|
@@ -1009,31 +1015,31 @@ describe Addressable::URI, "when created from string components" do
|
|
1009
1015
|
end
|
1010
1016
|
|
1011
1017
|
it "should raise an error if invalid components omitted" do
|
1012
|
-
expect
|
1018
|
+
expect do
|
1013
1019
|
@uri.omit(:bogus)
|
1014
|
-
end
|
1015
|
-
expect
|
1020
|
+
end.to raise_error(ArgumentError)
|
1021
|
+
expect do
|
1016
1022
|
@uri.omit(:scheme, :bogus, :path)
|
1017
|
-
end
|
1023
|
+
end.to raise_error(ArgumentError)
|
1018
1024
|
end
|
1019
1025
|
end
|
1020
1026
|
|
1021
1027
|
describe Addressable::URI, "when created with a nil host but " +
|
1022
1028
|
"non-nil authority components" do
|
1023
1029
|
it "should raise an error" do
|
1024
|
-
expect
|
1030
|
+
expect do
|
1025
1031
|
Addressable::URI.new(:user => "user", :password => "pass", :port => 80)
|
1026
|
-
end
|
1032
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
1027
1033
|
end
|
1028
1034
|
end
|
1029
1035
|
|
1030
1036
|
describe Addressable::URI, "when created with both an authority and a user" do
|
1031
1037
|
it "should raise an error" do
|
1032
|
-
expect
|
1038
|
+
expect do
|
1033
1039
|
Addressable::URI.new(
|
1034
1040
|
:user => "user", :authority => "user@example.com:80"
|
1035
1041
|
)
|
1036
|
-
end
|
1042
|
+
end.to raise_error(ArgumentError)
|
1037
1043
|
end
|
1038
1044
|
end
|
1039
1045
|
|
@@ -1071,33 +1077,33 @@ end
|
|
1071
1077
|
|
1072
1078
|
describe Addressable::URI, "when created with a host with a backslash" do
|
1073
1079
|
it "should raise an error" do
|
1074
|
-
expect
|
1080
|
+
expect do
|
1075
1081
|
Addressable::URI.new(:authority => "example\\example")
|
1076
|
-
end
|
1082
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
1077
1083
|
end
|
1078
1084
|
end
|
1079
1085
|
|
1080
1086
|
describe Addressable::URI, "when created with a host with a slash" do
|
1081
1087
|
it "should raise an error" do
|
1082
|
-
expect
|
1088
|
+
expect do
|
1083
1089
|
Addressable::URI.new(:authority => "example/example")
|
1084
|
-
end
|
1090
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
1085
1091
|
end
|
1086
1092
|
end
|
1087
1093
|
|
1088
1094
|
describe Addressable::URI, "when created with a host with a space" do
|
1089
1095
|
it "should raise an error" do
|
1090
|
-
expect
|
1096
|
+
expect do
|
1091
1097
|
Addressable::URI.new(:authority => "example example")
|
1092
|
-
end
|
1098
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
1093
1099
|
end
|
1094
1100
|
end
|
1095
1101
|
|
1096
1102
|
describe Addressable::URI, "when created with both a userinfo and a user" do
|
1097
1103
|
it "should raise an error" do
|
1098
|
-
expect
|
1104
|
+
expect do
|
1099
1105
|
Addressable::URI.new(:user => "user", :userinfo => "user:pass")
|
1100
|
-
end
|
1106
|
+
end.to raise_error(ArgumentError)
|
1101
1107
|
end
|
1102
1108
|
end
|
1103
1109
|
|
@@ -1189,18 +1195,18 @@ describe Addressable::URI, "when parsed from something that looks " +
|
|
1189
1195
|
"like a URI object" do
|
1190
1196
|
it "should parse without error" do
|
1191
1197
|
uri = Addressable::URI.parse(Fake::URI::HTTP.new("http://example.com/"))
|
1192
|
-
expect
|
1198
|
+
expect do
|
1193
1199
|
Addressable::URI.parse(uri)
|
1194
|
-
end
|
1200
|
+
end.not_to raise_error
|
1195
1201
|
end
|
1196
1202
|
end
|
1197
1203
|
|
1198
1204
|
describe Addressable::URI, "when parsed from a standard library URI object" do
|
1199
1205
|
it "should parse without error" do
|
1200
1206
|
uri = Addressable::URI.parse(URI.parse("http://example.com/"))
|
1201
|
-
expect
|
1207
|
+
expect do
|
1202
1208
|
Addressable::URI.parse(uri)
|
1203
|
-
end
|
1209
|
+
end.not_to raise_error
|
1204
1210
|
end
|
1205
1211
|
end
|
1206
1212
|
|
@@ -1360,9 +1366,9 @@ describe Addressable::URI, "when parsed from " +
|
|
1360
1366
|
end
|
1361
1367
|
|
1362
1368
|
it "should not allow request URI assignment" do
|
1363
|
-
expect
|
1369
|
+
expect do
|
1364
1370
|
@uri.request_uri = "/"
|
1365
|
-
end
|
1371
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
1366
1372
|
end
|
1367
1373
|
|
1368
1374
|
it "should have a query of 'objectClass?one'" do
|
@@ -1384,9 +1390,9 @@ describe Addressable::URI, "when parsed from " +
|
|
1384
1390
|
end
|
1385
1391
|
|
1386
1392
|
it "should raise an error if omission would create an invalid URI" do
|
1387
|
-
expect
|
1393
|
+
expect do
|
1388
1394
|
@uri.omit(:authority, :path)
|
1389
|
-
end
|
1395
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
1390
1396
|
end
|
1391
1397
|
|
1392
1398
|
it "should have an origin of 'ldap://[2001:db8::7]'" do
|
@@ -1772,9 +1778,9 @@ describe Addressable::URI, "when parsed from " +
|
|
1772
1778
|
|
1773
1779
|
it "should not be roughly equal to the string " +
|
1774
1780
|
"'http://example.com:bogus/'" do
|
1775
|
-
expect
|
1781
|
+
expect do
|
1776
1782
|
expect(@uri === "http://example.com:bogus/").to eq(false)
|
1777
|
-
end
|
1783
|
+
end.not_to raise_error
|
1778
1784
|
end
|
1779
1785
|
|
1780
1786
|
it "should result in itself when joined with itself" do
|
@@ -1804,21 +1810,21 @@ describe Addressable::URI, "when parsed from " +
|
|
1804
1810
|
end
|
1805
1811
|
|
1806
1812
|
it "should not allow origin assignment without scheme" do
|
1807
|
-
expect
|
1813
|
+
expect do
|
1808
1814
|
@uri.origin = "example.com"
|
1809
|
-
end
|
1815
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
1810
1816
|
end
|
1811
1817
|
|
1812
1818
|
it "should not allow origin assignment without host" do
|
1813
|
-
expect
|
1819
|
+
expect do
|
1814
1820
|
@uri.origin = "http://"
|
1815
|
-
end
|
1821
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
1816
1822
|
end
|
1817
1823
|
|
1818
1824
|
it "should not allow origin assignment with bogus type" do
|
1819
|
-
expect
|
1825
|
+
expect do
|
1820
1826
|
@uri.origin = :bogus
|
1821
|
-
end
|
1827
|
+
end.to raise_error(TypeError)
|
1822
1828
|
end
|
1823
1829
|
|
1824
1830
|
# Section 6.2.3 of RFC 3986
|
@@ -1874,9 +1880,9 @@ describe Addressable::URI, "when parsed from " +
|
|
1874
1880
|
end
|
1875
1881
|
|
1876
1882
|
it "when joined with a bogus object a TypeError should be raised" do
|
1877
|
-
expect
|
1883
|
+
expect do
|
1878
1884
|
@uri.join(42)
|
1879
|
-
end
|
1885
|
+
end.to raise_error(TypeError)
|
1880
1886
|
end
|
1881
1887
|
|
1882
1888
|
it "should have the correct username after assignment" do
|
@@ -1971,15 +1977,29 @@ end
|
|
1971
1977
|
|
1972
1978
|
# Section 5.1.2 of RFC 2616
|
1973
1979
|
describe Addressable::URI, "when parsed from " +
|
1974
|
-
"'
|
1980
|
+
"'HTTP://www.w3.org/pub/WWW/TheProject.html'" do
|
1975
1981
|
before do
|
1976
|
-
@uri = Addressable::URI.parse("
|
1982
|
+
@uri = Addressable::URI.parse("HTTP://www.w3.org/pub/WWW/TheProject.html")
|
1977
1983
|
end
|
1978
1984
|
|
1979
1985
|
it "should have the correct request URI" do
|
1980
1986
|
expect(@uri.request_uri).to eq("/pub/WWW/TheProject.html")
|
1981
1987
|
end
|
1982
1988
|
|
1989
|
+
it "should have the correct request URI after assignment" do
|
1990
|
+
@uri.request_uri = "/pub/WWW/TheProject.html?"
|
1991
|
+
expect(@uri.request_uri).to eq("/pub/WWW/TheProject.html?")
|
1992
|
+
expect(@uri.path).to eq("/pub/WWW/TheProject.html")
|
1993
|
+
expect(@uri.query).to eq("")
|
1994
|
+
end
|
1995
|
+
|
1996
|
+
it "should have the correct request URI after assignment" do
|
1997
|
+
@uri.request_uri = "/some/where/else.html"
|
1998
|
+
expect(@uri.request_uri).to eq("/some/where/else.html")
|
1999
|
+
expect(@uri.path).to eq("/some/where/else.html")
|
2000
|
+
expect(@uri.query).to eq(nil)
|
2001
|
+
end
|
2002
|
+
|
1983
2003
|
it "should have the correct request URI after assignment" do
|
1984
2004
|
@uri.request_uri = "/some/where/else.html?query?string"
|
1985
2005
|
expect(@uri.request_uri).to eq("/some/where/else.html?query?string")
|
@@ -1995,20 +2015,20 @@ describe Addressable::URI, "when parsed from " +
|
|
1995
2015
|
end
|
1996
2016
|
|
1997
2017
|
it "should raise an error if the site value is set to something bogus" do
|
1998
|
-
expect
|
2018
|
+
expect do
|
1999
2019
|
@uri.site = 42
|
2000
|
-
end
|
2020
|
+
end.to raise_error(TypeError)
|
2001
2021
|
end
|
2002
2022
|
|
2003
2023
|
it "should raise an error if the request URI is set to something bogus" do
|
2004
|
-
expect
|
2024
|
+
expect do
|
2005
2025
|
@uri.request_uri = 42
|
2006
|
-
end
|
2026
|
+
end.to raise_error(TypeError)
|
2007
2027
|
end
|
2008
2028
|
|
2009
2029
|
it "should correctly convert to a hash" do
|
2010
2030
|
expect(@uri.to_hash).to eq({
|
2011
|
-
:scheme => "
|
2031
|
+
:scheme => "HTTP",
|
2012
2032
|
:user => nil,
|
2013
2033
|
:password => nil,
|
2014
2034
|
:host => "www.w3.org",
|
@@ -2052,9 +2072,9 @@ describe Addressable::URI, "when parsing IPv6 addresses" do
|
|
2052
2072
|
|
2053
2073
|
it "should raise an error for " +
|
2054
2074
|
"'http://[<invalid>]/'" do
|
2055
|
-
expect
|
2075
|
+
expect do
|
2056
2076
|
Addressable::URI.parse("http://[<invalid>]/")
|
2057
|
-
end
|
2077
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
2058
2078
|
end
|
2059
2079
|
end
|
2060
2080
|
|
@@ -2080,9 +2100,9 @@ describe Addressable::URI, "when assigning IPv6 address" do
|
|
2080
2100
|
it "should not allow to set bare IPv6 address as host" do
|
2081
2101
|
uri = Addressable::URI.parse("http://[::1]/")
|
2082
2102
|
skip "not checked"
|
2083
|
-
expect
|
2103
|
+
expect do
|
2084
2104
|
uri.host = '3ffe:1900:4545:3:200:f8ff:fe21:67cf'
|
2085
|
-
end
|
2105
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
2086
2106
|
end
|
2087
2107
|
end
|
2088
2108
|
|
@@ -2114,9 +2134,9 @@ describe Addressable::URI, "when parsing IPvFuture addresses" do
|
|
2114
2134
|
|
2115
2135
|
it "should raise an error for " +
|
2116
2136
|
"'http://[v0.<invalid>]/'" do
|
2117
|
-
expect
|
2137
|
+
expect do
|
2118
2138
|
Addressable::URI.parse("http://[v0.<invalid>]/")
|
2119
|
-
end
|
2139
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
2120
2140
|
end
|
2121
2141
|
end
|
2122
2142
|
|
@@ -2460,9 +2480,9 @@ describe Addressable::URI, "when parsed from " +
|
|
2460
2480
|
end
|
2461
2481
|
|
2462
2482
|
it "should not raise an exception when normalized" do
|
2463
|
-
expect
|
2483
|
+
expect do
|
2464
2484
|
@uri.normalize
|
2465
|
-
end
|
2485
|
+
end.not_to raise_error
|
2466
2486
|
end
|
2467
2487
|
|
2468
2488
|
it "should be considered to be in normal form" do
|
@@ -2514,9 +2534,9 @@ describe Addressable::URI, "when parsed from " +
|
|
2514
2534
|
end
|
2515
2535
|
|
2516
2536
|
it "should not raise an exception when normalized" do
|
2517
|
-
expect
|
2537
|
+
expect do
|
2518
2538
|
@uri.normalize
|
2519
|
-
end
|
2539
|
+
end.not_to raise_error
|
2520
2540
|
end
|
2521
2541
|
|
2522
2542
|
it "should be considered to be in normal form" do
|
@@ -2539,9 +2559,9 @@ describe Addressable::URI, "when parsed from " +
|
|
2539
2559
|
end
|
2540
2560
|
|
2541
2561
|
it "should not raise an exception when normalized" do
|
2542
|
-
expect
|
2562
|
+
expect do
|
2543
2563
|
@uri.normalize
|
2544
|
-
end
|
2564
|
+
end.not_to raise_error
|
2545
2565
|
end
|
2546
2566
|
|
2547
2567
|
it "should be considered to be in normal form" do
|
@@ -2577,9 +2597,9 @@ describe Addressable::URI, "when parsed from " +
|
|
2577
2597
|
end
|
2578
2598
|
|
2579
2599
|
it "should raise an error if encoding with an unexpected return type" do
|
2580
|
-
expect
|
2600
|
+
expect do
|
2581
2601
|
Addressable::URI.normalized_encode(@uri, Integer)
|
2582
|
-
end
|
2602
|
+
end.to raise_error(TypeError)
|
2583
2603
|
end
|
2584
2604
|
|
2585
2605
|
it "if percent encoded should be 'http://example.com/C%25CC%25A7'" do
|
@@ -2595,9 +2615,9 @@ describe Addressable::URI, "when parsed from " +
|
|
2595
2615
|
end
|
2596
2616
|
|
2597
2617
|
it "should raise an error if encoding with an unexpected return type" do
|
2598
|
-
expect
|
2618
|
+
expect do
|
2599
2619
|
Addressable::URI.encode(@uri, Integer)
|
2600
|
-
end
|
2620
|
+
end.to raise_error(TypeError)
|
2601
2621
|
end
|
2602
2622
|
|
2603
2623
|
it "should be identical to its duplicate" do
|
@@ -2732,9 +2752,9 @@ describe Addressable::URI, "when parsed from " +
|
|
2732
2752
|
|
2733
2753
|
it "should not be roughly equal to the string " +
|
2734
2754
|
"'http://example.com:bogus/'" do
|
2735
|
-
expect
|
2755
|
+
expect do
|
2736
2756
|
expect(@uri === "http://example.com:bogus/").to eq(false)
|
2737
|
-
end
|
2757
|
+
end.not_to raise_error
|
2738
2758
|
end
|
2739
2759
|
|
2740
2760
|
it "should result in itself when joined with itself" do
|
@@ -3080,9 +3100,9 @@ describe Addressable::URI, "when parsed from " +
|
|
3080
3100
|
end
|
3081
3101
|
|
3082
3102
|
it "should become invalid when normalized" do
|
3083
|
-
expect
|
3103
|
+
expect do
|
3084
3104
|
@uri.normalize
|
3085
|
-
end
|
3105
|
+
end.to raise_error(Addressable::URI::InvalidURIError, /authority/)
|
3086
3106
|
end
|
3087
3107
|
|
3088
3108
|
it "should have a path of '/..//example.com'" do
|
@@ -3320,12 +3340,12 @@ describe Addressable::URI, "when parsed from " +
|
|
3320
3340
|
end
|
3321
3341
|
|
3322
3342
|
it "should raise an error if routing is attempted" do
|
3323
|
-
expect
|
3343
|
+
expect do
|
3324
3344
|
@uri.route_to("http://example.com/")
|
3325
|
-
end
|
3326
|
-
expect
|
3345
|
+
end.to raise_error(ArgumentError, /relative\/path\/to\/resource/)
|
3346
|
+
expect do
|
3327
3347
|
@uri.route_from("http://example.com/")
|
3328
|
-
end
|
3348
|
+
end.to raise_error(ArgumentError, /relative\/path\/to\/resource/)
|
3329
3349
|
end
|
3330
3350
|
|
3331
3351
|
it "when joined with 'another/relative/path' should be " +
|
@@ -3922,9 +3942,9 @@ describe Addressable::URI, "when parsed from " +
|
|
3922
3942
|
end
|
3923
3943
|
|
3924
3944
|
it "should raise an error if assigning a bogus object to the hostname" do
|
3925
|
-
expect
|
3945
|
+
expect do
|
3926
3946
|
@uri.hostname = Object.new
|
3927
|
-
end
|
3947
|
+
end.to raise_error(TypeError)
|
3928
3948
|
end
|
3929
3949
|
|
3930
3950
|
it "should have the correct port after assignment" do
|
@@ -4003,9 +4023,9 @@ describe Addressable::URI, "when parsed from " +
|
|
4003
4023
|
end
|
4004
4024
|
|
4005
4025
|
it "should raise an error if query values are set to a bogus type" do
|
4006
|
-
expect
|
4026
|
+
expect do
|
4007
4027
|
@uri.query_values = "bogus"
|
4008
|
-
end
|
4028
|
+
end.to raise_error(TypeError)
|
4009
4029
|
end
|
4010
4030
|
|
4011
4031
|
it "should have the correct fragment after assignment" do
|
@@ -4077,39 +4097,39 @@ describe Addressable::URI, "when parsed from " +
|
|
4077
4097
|
end
|
4078
4098
|
|
4079
4099
|
it "should fail to merge with bogus values" do
|
4080
|
-
expect
|
4100
|
+
expect do
|
4081
4101
|
@uri.merge(:port => "bogus")
|
4082
|
-
end
|
4102
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
4083
4103
|
end
|
4084
4104
|
|
4085
4105
|
it "should fail to merge with bogus values" do
|
4086
|
-
expect
|
4106
|
+
expect do
|
4087
4107
|
@uri.merge(:authority => "bar@baz:bogus")
|
4088
|
-
end
|
4108
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
4089
4109
|
end
|
4090
4110
|
|
4091
4111
|
it "should fail to merge with bogus parameters" do
|
4092
|
-
expect
|
4112
|
+
expect do
|
4093
4113
|
@uri.merge(42)
|
4094
|
-
end
|
4114
|
+
end.to raise_error(TypeError)
|
4095
4115
|
end
|
4096
4116
|
|
4097
4117
|
it "should fail to merge with bogus parameters" do
|
4098
|
-
expect
|
4118
|
+
expect do
|
4099
4119
|
@uri.merge("http://example.com/")
|
4100
|
-
end
|
4120
|
+
end.to raise_error(TypeError)
|
4101
4121
|
end
|
4102
4122
|
|
4103
4123
|
it "should fail to merge with both authority and subcomponents" do
|
4104
|
-
expect
|
4124
|
+
expect do
|
4105
4125
|
@uri.merge(:authority => "foo:bar@baz:42", :port => "42")
|
4106
|
-
end
|
4126
|
+
end.to raise_error(ArgumentError)
|
4107
4127
|
end
|
4108
4128
|
|
4109
4129
|
it "should fail to merge with both userinfo and subcomponents" do
|
4110
|
-
expect
|
4130
|
+
expect do
|
4111
4131
|
@uri.merge(:userinfo => "foo:bar", :user => "foo")
|
4112
|
-
end
|
4132
|
+
end.to raise_error(ArgumentError)
|
4113
4133
|
end
|
4114
4134
|
|
4115
4135
|
it "should be identical to its duplicate" do
|
@@ -4242,6 +4262,36 @@ describe Addressable::URI, "when parsed from " +
|
|
4242
4262
|
end
|
4243
4263
|
end
|
4244
4264
|
|
4265
|
+
describe Addressable::URI, "when parsed from 'https://example.com/?q=a+b'" do
|
4266
|
+
before do
|
4267
|
+
@uri = Addressable::URI.parse("https://example.com/?q=a+b")
|
4268
|
+
end
|
4269
|
+
|
4270
|
+
it "should have query_values of {'q' => 'a b'}" do
|
4271
|
+
expect(@uri.query_values).to eq("q" => "a b")
|
4272
|
+
end
|
4273
|
+
end
|
4274
|
+
|
4275
|
+
describe Addressable::URI, "when parsed from 'example.com?q=a+b'" do
|
4276
|
+
before do
|
4277
|
+
@uri = Addressable::URI.parse("example.com?q=a+b")
|
4278
|
+
end
|
4279
|
+
|
4280
|
+
it "should have query_values of {'q' => 'a b'}" do
|
4281
|
+
expect(@uri.query_values).to eq("q" => "a b")
|
4282
|
+
end
|
4283
|
+
end
|
4284
|
+
|
4285
|
+
describe Addressable::URI, "when parsed from 'mailto:?q=a+b'" do
|
4286
|
+
before do
|
4287
|
+
@uri = Addressable::URI.parse("mailto:?q=a+b")
|
4288
|
+
end
|
4289
|
+
|
4290
|
+
it "should have query_values of {'q' => 'a+b'}" do
|
4291
|
+
expect(@uri.query_values).to eq("q" => "a+b")
|
4292
|
+
end
|
4293
|
+
end
|
4294
|
+
|
4245
4295
|
describe Addressable::URI, "when parsed from " +
|
4246
4296
|
"'http://example.com/?q=a%2bb'" do
|
4247
4297
|
before do
|
@@ -4283,6 +4333,46 @@ describe Addressable::URI, "when parsed from " +
|
|
4283
4333
|
end
|
4284
4334
|
end
|
4285
4335
|
|
4336
|
+
describe Addressable::URI, "when parsed from 'http://example/?b=1&a=2&c=3'" do
|
4337
|
+
before do
|
4338
|
+
@uri = Addressable::URI.parse("http://example/?b=1&a=2&c=3")
|
4339
|
+
end
|
4340
|
+
|
4341
|
+
it "should have a sorted normalized query of 'a=2&b=1&c=3'" do
|
4342
|
+
expect(@uri.normalized_query(:sorted)).to eq("a=2&b=1&c=3")
|
4343
|
+
end
|
4344
|
+
end
|
4345
|
+
|
4346
|
+
describe Addressable::URI, "when parsed from 'http://example/?&a&&c&'" do
|
4347
|
+
before do
|
4348
|
+
@uri = Addressable::URI.parse("http://example/?&a&&c&")
|
4349
|
+
end
|
4350
|
+
|
4351
|
+
it "should have a compacted normalized query of 'a&c'" do
|
4352
|
+
expect(@uri.normalized_query(:compacted)).to eq("a&c")
|
4353
|
+
end
|
4354
|
+
end
|
4355
|
+
|
4356
|
+
describe Addressable::URI, "when parsed from 'http://example.com/?a=1&a=1'" do
|
4357
|
+
before do
|
4358
|
+
@uri = Addressable::URI.parse("http://example.com/?a=1&a=1")
|
4359
|
+
end
|
4360
|
+
|
4361
|
+
it "should have a compacted normalized query of 'a=1'" do
|
4362
|
+
expect(@uri.normalized_query(:compacted)).to eq("a=1")
|
4363
|
+
end
|
4364
|
+
end
|
4365
|
+
|
4366
|
+
describe Addressable::URI, "when parsed from 'http://example.com/?a=1&a=2'" do
|
4367
|
+
before do
|
4368
|
+
@uri = Addressable::URI.parse("http://example.com/?a=1&a=2")
|
4369
|
+
end
|
4370
|
+
|
4371
|
+
it "should have a compacted normalized query of 'a=1&a=2'" do
|
4372
|
+
expect(@uri.normalized_query(:compacted)).to eq("a=1&a=2")
|
4373
|
+
end
|
4374
|
+
end
|
4375
|
+
|
4286
4376
|
describe Addressable::URI, "when parsed from " +
|
4287
4377
|
"'http://example.com/sound%2bvision'" do
|
4288
4378
|
before do
|
@@ -4394,10 +4484,10 @@ describe Addressable::URI, "when parsed from " +
|
|
4394
4484
|
end
|
4395
4485
|
|
4396
4486
|
it "should raise an error after nil assignment of authority segment" do
|
4397
|
-
expect
|
4487
|
+
expect do
|
4398
4488
|
# This would create an invalid URI
|
4399
4489
|
@uri.authority = nil
|
4400
|
-
end
|
4490
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
4401
4491
|
end
|
4402
4492
|
end
|
4403
4493
|
|
@@ -4626,12 +4716,12 @@ describe Addressable::URI, "when parsed from " +
|
|
4626
4716
|
end
|
4627
4717
|
|
4628
4718
|
it "should raise an error if routing is attempted" do
|
4629
|
-
expect
|
4719
|
+
expect do
|
4630
4720
|
@uri.route_to("http://example.com/")
|
4631
|
-
end
|
4632
|
-
expect
|
4721
|
+
end.to raise_error(ArgumentError, /\/\/example.com\//)
|
4722
|
+
expect do
|
4633
4723
|
@uri.route_from("http://example.com/")
|
4634
|
-
end
|
4724
|
+
end.to raise_error(ArgumentError, /\/\/example.com\//)
|
4635
4725
|
end
|
4636
4726
|
|
4637
4727
|
it "should have a 'null' origin" do
|
@@ -4725,9 +4815,9 @@ end
|
|
4725
4815
|
describe Addressable::URI, "when parsed from " +
|
4726
4816
|
"'http://under_score.example.com/'" do
|
4727
4817
|
it "should not cause an error" do
|
4728
|
-
expect
|
4818
|
+
expect do
|
4729
4819
|
Addressable::URI.parse("http://under_score.example.com/")
|
4730
|
-
end
|
4820
|
+
end.not_to raise_error
|
4731
4821
|
end
|
4732
4822
|
end
|
4733
4823
|
|
@@ -4799,9 +4889,9 @@ describe Addressable::URI, "when parsed from '?one=1&two=2&three=3'" do
|
|
4799
4889
|
end
|
4800
4890
|
|
4801
4891
|
it "should raise an error for invalid return type values" do
|
4802
|
-
expect
|
4803
|
-
@uri.query_values(
|
4804
|
-
end
|
4892
|
+
expect do
|
4893
|
+
@uri.query_values(Integer)
|
4894
|
+
end.to raise_error(ArgumentError)
|
4805
4895
|
end
|
4806
4896
|
|
4807
4897
|
it "should have the correct array query values" do
|
@@ -5402,9 +5492,9 @@ describe Addressable::URI, "with a base uri of 'http://a/b/c/d;p?q'" do
|
|
5402
5492
|
end
|
5403
5493
|
|
5404
5494
|
it "when joined with a bogus object a TypeError should be raised" do
|
5405
|
-
expect
|
5495
|
+
expect do
|
5406
5496
|
Addressable::URI.join(@uri, 42)
|
5407
|
-
end
|
5497
|
+
end.to raise_error(TypeError)
|
5408
5498
|
end
|
5409
5499
|
end
|
5410
5500
|
|
@@ -5431,9 +5521,9 @@ end
|
|
5431
5521
|
|
5432
5522
|
describe Addressable::URI, "when converting a bogus path" do
|
5433
5523
|
it "should raise a TypeError" do
|
5434
|
-
expect
|
5524
|
+
expect do
|
5435
5525
|
Addressable::URI.convert_path(42)
|
5436
|
-
end
|
5526
|
+
end.to raise_error(TypeError)
|
5437
5527
|
end
|
5438
5528
|
end
|
5439
5529
|
|
@@ -5486,6 +5576,31 @@ describe Addressable::URI, "when given the path '/one/two/'" do
|
|
5486
5576
|
end
|
5487
5577
|
end
|
5488
5578
|
|
5579
|
+
describe Addressable::URI, "when given the tld " do
|
5580
|
+
it "'uk' should have a tld of 'uk'" do
|
5581
|
+
uri = Addressable::URI.parse("http://example.com")
|
5582
|
+
uri.tld = "uk"
|
5583
|
+
|
5584
|
+
expect(uri.tld).to eq("uk")
|
5585
|
+
end
|
5586
|
+
|
5587
|
+
context "which " do
|
5588
|
+
let (:uri) { Addressable::URI.parse("http://www.comrade.net/path/to/source/") }
|
5589
|
+
|
5590
|
+
it "contains a subdomain" do
|
5591
|
+
uri.tld = "co.uk"
|
5592
|
+
|
5593
|
+
expect(uri.to_s).to eq("http://www.comrade.co.uk/path/to/source/")
|
5594
|
+
end
|
5595
|
+
|
5596
|
+
it "is part of the domain" do
|
5597
|
+
uri.tld = "com"
|
5598
|
+
|
5599
|
+
expect(uri.to_s).to eq("http://www.comrade.com/path/to/source/")
|
5600
|
+
end
|
5601
|
+
end
|
5602
|
+
end
|
5603
|
+
|
5489
5604
|
describe Addressable::URI, "when given the path " +
|
5490
5605
|
"'c:\\windows\\My Documents 100%20\\foo.txt'" do
|
5491
5606
|
before do
|
@@ -5603,9 +5718,9 @@ describe Addressable::URI, "when parsing a non-String object" do
|
|
5603
5718
|
end
|
5604
5719
|
|
5605
5720
|
it "should raise a TypeError for objects than cannot be converted" do
|
5606
|
-
expect
|
5721
|
+
expect do
|
5607
5722
|
Addressable::URI.parse(42)
|
5608
|
-
end
|
5723
|
+
end.to raise_error(TypeError)
|
5609
5724
|
end
|
5610
5725
|
|
5611
5726
|
it "should correctly parse heuristically anything with a 'to_str' method" do
|
@@ -5613,9 +5728,9 @@ describe Addressable::URI, "when parsing a non-String object" do
|
|
5613
5728
|
end
|
5614
5729
|
|
5615
5730
|
it "should raise a TypeError for objects than cannot be converted" do
|
5616
|
-
expect
|
5731
|
+
expect do
|
5617
5732
|
Addressable::URI.heuristic_parse(42)
|
5618
|
-
end
|
5733
|
+
end.to raise_error(TypeError)
|
5619
5734
|
end
|
5620
5735
|
end
|
5621
5736
|
|
@@ -5659,9 +5774,9 @@ end
|
|
5659
5774
|
|
5660
5775
|
describe Addressable::URI, "when form encoding a non-Array object" do
|
5661
5776
|
it "should raise a TypeError for objects than cannot be converted" do
|
5662
|
-
expect
|
5777
|
+
expect do
|
5663
5778
|
Addressable::URI.form_encode(42)
|
5664
|
-
end
|
5779
|
+
end.to raise_error(TypeError)
|
5665
5780
|
end
|
5666
5781
|
end
|
5667
5782
|
|
@@ -5727,9 +5842,9 @@ describe Addressable::URI, "when form unencoding a non-String object" do
|
|
5727
5842
|
end
|
5728
5843
|
|
5729
5844
|
it "should raise a TypeError for objects than cannot be converted" do
|
5730
|
-
expect
|
5845
|
+
expect do
|
5731
5846
|
Addressable::URI.form_unencode(42)
|
5732
|
-
end
|
5847
|
+
end.to raise_error(TypeError)
|
5733
5848
|
end
|
5734
5849
|
end
|
5735
5850
|
|
@@ -5739,15 +5854,15 @@ describe Addressable::URI, "when normalizing a non-String object" do
|
|
5739
5854
|
end
|
5740
5855
|
|
5741
5856
|
it "should raise a TypeError for objects than cannot be converted" do
|
5742
|
-
expect
|
5857
|
+
expect do
|
5743
5858
|
Addressable::URI.normalize_component(42)
|
5744
|
-
end
|
5859
|
+
end.to raise_error(TypeError)
|
5745
5860
|
end
|
5746
5861
|
|
5747
5862
|
it "should raise a TypeError for objects than cannot be converted" do
|
5748
|
-
expect
|
5863
|
+
expect do
|
5749
5864
|
Addressable::URI.normalize_component("component", 42)
|
5750
|
-
end
|
5865
|
+
end.to raise_error(TypeError)
|
5751
5866
|
end
|
5752
5867
|
end
|
5753
5868
|
|
@@ -5819,6 +5934,18 @@ describe Addressable::URI, "when normalizing a string but leaving some character
|
|
5819
5934
|
end
|
5820
5935
|
end
|
5821
5936
|
|
5937
|
+
describe Addressable::URI, "when encoding IP literals" do
|
5938
|
+
it "should work for IPv4" do
|
5939
|
+
input = "http://127.0.0.1/"
|
5940
|
+
expect(Addressable::URI.encode(input)).to eq(input)
|
5941
|
+
end
|
5942
|
+
|
5943
|
+
it "should work for IPv6" do
|
5944
|
+
input = "http://[fe80::200:f8ff:fe21:67cf]/"
|
5945
|
+
expect(Addressable::URI.encode(input)).to eq(input)
|
5946
|
+
end
|
5947
|
+
end
|
5948
|
+
|
5822
5949
|
describe Addressable::URI, "when encoding a string with existing encodings to upcase" do
|
5823
5950
|
it "should result in correct percent encoded sequence" do
|
5824
5951
|
expect(Addressable::URI.encode_component("JK%4c", "0-9A-IKM-Za-z%", "L")).to eq("%4AK%4C")
|
@@ -5891,41 +6018,41 @@ end
|
|
5891
6018
|
|
5892
6019
|
describe Addressable::URI, "when unencoding a bogus object" do
|
5893
6020
|
it "should raise a TypeError" do
|
5894
|
-
expect
|
6021
|
+
expect do
|
5895
6022
|
Addressable::URI.unencode_component(42)
|
5896
|
-
end
|
6023
|
+
end.to raise_error(TypeError)
|
5897
6024
|
end
|
5898
6025
|
|
5899
6026
|
it "should raise a TypeError" do
|
5900
|
-
expect
|
6027
|
+
expect do
|
5901
6028
|
Addressable::URI.unencode("/path?g%C3%BCnther", Integer)
|
5902
|
-
end
|
6029
|
+
end.to raise_error(TypeError)
|
5903
6030
|
end
|
5904
6031
|
end
|
5905
6032
|
|
5906
6033
|
describe Addressable::URI, "when encoding a bogus object" do
|
5907
6034
|
it "should raise a TypeError" do
|
5908
|
-
expect
|
6035
|
+
expect do
|
5909
6036
|
Addressable::URI.encode(Object.new)
|
5910
|
-
end
|
6037
|
+
end.to raise_error(TypeError)
|
5911
6038
|
end
|
5912
6039
|
|
5913
6040
|
it "should raise a TypeError" do
|
5914
|
-
expect
|
6041
|
+
expect do
|
5915
6042
|
Addressable::URI.normalized_encode(Object.new)
|
5916
|
-
end
|
6043
|
+
end.to raise_error(TypeError)
|
5917
6044
|
end
|
5918
6045
|
|
5919
6046
|
it "should raise a TypeError" do
|
5920
|
-
expect
|
6047
|
+
expect do
|
5921
6048
|
Addressable::URI.encode_component("günther", Object.new)
|
5922
|
-
end
|
6049
|
+
end.to raise_error(TypeError)
|
5923
6050
|
end
|
5924
6051
|
|
5925
6052
|
it "should raise a TypeError" do
|
5926
|
-
expect
|
6053
|
+
expect do
|
5927
6054
|
Addressable::URI.encode_component(Object.new)
|
5928
|
-
end
|
6055
|
+
end.to raise_error(TypeError)
|
5929
6056
|
end
|
5930
6057
|
end
|
5931
6058
|
|
@@ -5941,9 +6068,9 @@ describe Addressable::URI, "when given the input " +
|
|
5941
6068
|
end
|
5942
6069
|
|
5943
6070
|
it "should not raise error when frozen" do
|
5944
|
-
expect
|
6071
|
+
expect do
|
5945
6072
|
Addressable::URI.heuristic_parse(@input).freeze.to_s
|
5946
|
-
end
|
6073
|
+
end.not_to raise_error
|
5947
6074
|
end
|
5948
6075
|
end
|
5949
6076
|
|
@@ -6223,6 +6350,18 @@ describe Addressable::URI, "when given the input " +
|
|
6223
6350
|
end
|
6224
6351
|
end
|
6225
6352
|
|
6353
|
+
describe Addressable::URI, "when given the input which "\
|
6354
|
+
"start with digits and has specified port" do
|
6355
|
+
before do
|
6356
|
+
@input = "7777.example.org:8089"
|
6357
|
+
end
|
6358
|
+
|
6359
|
+
it "should heuristically parse to 'http://7777.example.org:8089'" do
|
6360
|
+
uri = Addressable::URI.heuristic_parse(@input)
|
6361
|
+
expect(uri.to_s).to eq("http://7777.example.org:8089")
|
6362
|
+
end
|
6363
|
+
end
|
6364
|
+
|
6226
6365
|
describe Addressable::URI, "when given the input " +
|
6227
6366
|
"'feed:///example.com'" do
|
6228
6367
|
before do
|
@@ -6235,6 +6374,18 @@ describe Addressable::URI, "when given the input " +
|
|
6235
6374
|
end
|
6236
6375
|
end
|
6237
6376
|
|
6377
|
+
describe Addressable::URI, "when given the input " +
|
6378
|
+
"'file://localhost/path/to/resource/'" do
|
6379
|
+
before do
|
6380
|
+
@input = "file://localhost/path/to/resource/"
|
6381
|
+
end
|
6382
|
+
|
6383
|
+
it "should heuristically parse to 'file:///path/to/resource/'" do
|
6384
|
+
@uri = Addressable::URI.heuristic_parse(@input)
|
6385
|
+
expect(@uri.to_s).to eq("file:///path/to/resource/")
|
6386
|
+
end
|
6387
|
+
end
|
6388
|
+
|
6238
6389
|
describe Addressable::URI, "when given the input " +
|
6239
6390
|
"'file://path/to/resource/'" do
|
6240
6391
|
before do
|
@@ -6247,6 +6398,18 @@ describe Addressable::URI, "when given the input " +
|
|
6247
6398
|
end
|
6248
6399
|
end
|
6249
6400
|
|
6401
|
+
describe Addressable::URI, "when given the input " +
|
6402
|
+
"'file://///path/to/resource/'" do
|
6403
|
+
before do
|
6404
|
+
@input = "file:///////path/to/resource/"
|
6405
|
+
end
|
6406
|
+
|
6407
|
+
it "should heuristically parse to 'file:////path/to/resource/'" do
|
6408
|
+
@uri = Addressable::URI.heuristic_parse(@input)
|
6409
|
+
expect(@uri.to_s).to eq("file:////path/to/resource/")
|
6410
|
+
end
|
6411
|
+
end
|
6412
|
+
|
6250
6413
|
describe Addressable::URI, "when given the input " +
|
6251
6414
|
"'feed://http://example.com'" do
|
6252
6415
|
before do
|
@@ -6271,6 +6434,44 @@ describe Addressable::URI, "when given the input " +
|
|
6271
6434
|
end
|
6272
6435
|
end
|
6273
6436
|
|
6437
|
+
describe Addressable::URI, "when given the input: 'user@domain.com'" do
|
6438
|
+
before do
|
6439
|
+
@input = "user@domain.com"
|
6440
|
+
end
|
6441
|
+
|
6442
|
+
context "for heuristic parse" do
|
6443
|
+
it "should remain 'mailto:user@domain.com'" do
|
6444
|
+
uri = Addressable::URI.heuristic_parse("mailto:#{@input}")
|
6445
|
+
expect(uri.to_s).to eq("mailto:user@domain.com")
|
6446
|
+
end
|
6447
|
+
|
6448
|
+
it "should have a scheme of 'mailto'" do
|
6449
|
+
uri = Addressable::URI.heuristic_parse(@input)
|
6450
|
+
expect(uri.to_s).to eq("mailto:user@domain.com")
|
6451
|
+
expect(uri.scheme).to eq("mailto")
|
6452
|
+
end
|
6453
|
+
|
6454
|
+
it "should remain 'acct:user@domain.com'" do
|
6455
|
+
uri = Addressable::URI.heuristic_parse("acct:#{@input}")
|
6456
|
+
expect(uri.to_s).to eq("acct:user@domain.com")
|
6457
|
+
end
|
6458
|
+
|
6459
|
+
context "HTTP" do
|
6460
|
+
before do
|
6461
|
+
@uri = Addressable::URI.heuristic_parse("http://#{@input}/")
|
6462
|
+
end
|
6463
|
+
|
6464
|
+
it "should remain 'http://user@domain.com/'" do
|
6465
|
+
expect(@uri.to_s).to eq("http://user@domain.com/")
|
6466
|
+
end
|
6467
|
+
|
6468
|
+
it "should have the username 'user' for HTTP basic authentication" do
|
6469
|
+
expect(@uri.user).to eq("user")
|
6470
|
+
end
|
6471
|
+
end
|
6472
|
+
end
|
6473
|
+
end
|
6474
|
+
|
6274
6475
|
describe Addressable::URI, "when assigning query values" do
|
6275
6476
|
before do
|
6276
6477
|
@uri = Addressable::URI.new
|
@@ -6282,54 +6483,54 @@ describe Addressable::URI, "when assigning query values" do
|
|
6282
6483
|
end
|
6283
6484
|
|
6284
6485
|
it "should raise an error attempting to assign {'a' => {'b' => ['c']}}" do
|
6285
|
-
expect
|
6486
|
+
expect do
|
6286
6487
|
@uri.query_values = { 'a' => {'b' => ['c'] } }
|
6287
|
-
end
|
6488
|
+
end.to raise_error(TypeError)
|
6288
6489
|
end
|
6289
6490
|
|
6290
6491
|
it "should raise an error attempting to assign " +
|
6291
6492
|
"{:b => '2', :a => {:c => '1'}}" do
|
6292
|
-
expect
|
6493
|
+
expect do
|
6293
6494
|
@uri.query_values = {:b => '2', :a => {:c => '1'}}
|
6294
|
-
end
|
6495
|
+
end.to raise_error(TypeError)
|
6295
6496
|
end
|
6296
6497
|
|
6297
6498
|
it "should raise an error attempting to assign " +
|
6298
6499
|
"{:a => 'a', :b => [{:c => 'c', :d => 'd'}, " +
|
6299
6500
|
"{:e => 'e', :f => 'f'}]}" do
|
6300
|
-
expect
|
6501
|
+
expect do
|
6301
6502
|
@uri.query_values = {
|
6302
6503
|
:a => "a", :b => [{:c => "c", :d => "d"}, {:e => "e", :f => "f"}]
|
6303
6504
|
}
|
6304
|
-
end
|
6505
|
+
end.to raise_error(TypeError)
|
6305
6506
|
end
|
6306
6507
|
|
6307
6508
|
it "should raise an error attempting to assign " +
|
6308
6509
|
"{:a => 'a', :b => [{:c => true, :d => 'd'}, " +
|
6309
6510
|
"{:e => 'e', :f => 'f'}]}" do
|
6310
|
-
expect
|
6511
|
+
expect do
|
6311
6512
|
@uri.query_values = {
|
6312
6513
|
:a => 'a', :b => [{:c => true, :d => 'd'}, {:e => 'e', :f => 'f'}]
|
6313
6514
|
}
|
6314
|
-
end
|
6515
|
+
end.to raise_error(TypeError)
|
6315
6516
|
end
|
6316
6517
|
|
6317
6518
|
it "should raise an error attempting to assign " +
|
6318
6519
|
"{:a => 'a', :b => {:c => true, :d => 'd'}}" do
|
6319
|
-
expect
|
6520
|
+
expect do
|
6320
6521
|
@uri.query_values = {
|
6321
6522
|
:a => 'a', :b => {:c => true, :d => 'd'}
|
6322
6523
|
}
|
6323
|
-
end
|
6524
|
+
end.to raise_error(TypeError)
|
6324
6525
|
end
|
6325
6526
|
|
6326
6527
|
it "should raise an error attempting to assign " +
|
6327
6528
|
"{:a => 'a', :b => {:c => true, :d => 'd'}}" do
|
6328
|
-
expect
|
6529
|
+
expect do
|
6329
6530
|
@uri.query_values = {
|
6330
6531
|
:a => 'a', :b => {:c => true, :d => 'd'}
|
6331
6532
|
}
|
6332
|
-
end
|
6533
|
+
end.to raise_error(TypeError)
|
6333
6534
|
end
|
6334
6535
|
|
6335
6536
|
it "should correctly assign {:a => 1, :b => 1.5}" do
|
@@ -6340,13 +6541,13 @@ describe Addressable::URI, "when assigning query values" do
|
|
6340
6541
|
it "should raise an error attempting to assign " +
|
6341
6542
|
"{:z => 1, :f => [2, {999.1 => [3,'4']}, ['h', 'i']], " +
|
6342
6543
|
":a => {:b => ['c', 'd'], :e => true, :y => 0.5}}" do
|
6343
|
-
expect
|
6544
|
+
expect do
|
6344
6545
|
@uri.query_values = {
|
6345
6546
|
:z => 1,
|
6346
6547
|
:f => [ 2, {999.1 => [3,'4']}, ['h', 'i'] ],
|
6347
6548
|
:a => { :b => ['c', 'd'], :e => true, :y => 0.5 }
|
6348
6549
|
}
|
6349
|
-
end
|
6550
|
+
end.to raise_error(TypeError)
|
6350
6551
|
end
|
6351
6552
|
|
6352
6553
|
it "should correctly assign {}" do
|
@@ -6396,7 +6597,7 @@ describe Addressable::URI, "when assigning path values" do
|
|
6396
6597
|
@uri.path = "acct:bob@sporkmonger.com"
|
6397
6598
|
expect(@uri.path).to eq("acct:bob@sporkmonger.com")
|
6398
6599
|
expect(@uri.normalize.to_str).to eq("acct%2Fbob@sporkmonger.com")
|
6399
|
-
expect
|
6600
|
+
expect { @uri.to_s }.to raise_error(
|
6400
6601
|
Addressable::URI::InvalidURIError
|
6401
6602
|
)
|
6402
6603
|
end
|
@@ -6414,26 +6615,26 @@ describe Addressable::URI, "when assigning path values" do
|
|
6414
6615
|
end
|
6415
6616
|
|
6416
6617
|
it "should not allow relative paths to be assigned on absolute URIs" do
|
6417
|
-
expect
|
6618
|
+
expect do
|
6418
6619
|
@uri.scheme = "http"
|
6419
6620
|
@uri.host = "example.com"
|
6420
6621
|
@uri.path = "acct:bob@sporkmonger.com"
|
6421
|
-
end
|
6622
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
6422
6623
|
end
|
6423
6624
|
|
6424
6625
|
it "should not allow relative paths to be assigned on absolute URIs" do
|
6425
|
-
expect
|
6626
|
+
expect do
|
6426
6627
|
@uri.path = "acct:bob@sporkmonger.com"
|
6427
6628
|
@uri.scheme = "http"
|
6428
6629
|
@uri.host = "example.com"
|
6429
|
-
end
|
6630
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
6430
6631
|
end
|
6431
6632
|
|
6432
6633
|
it "should not allow relative paths to be assigned on absolute URIs" do
|
6433
|
-
expect
|
6634
|
+
expect do
|
6434
6635
|
@uri.path = "uuid:0b3ecf60-3f93-11df-a9c3-001f5bfffe12"
|
6435
6636
|
@uri.scheme = "urn"
|
6436
|
-
end
|
6637
|
+
end.not_to raise_error
|
6437
6638
|
end
|
6438
6639
|
end
|
6439
6640
|
|