addressabler 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.markdown +39 -0
- data/lib/addressabler/query.rb +23 -0
- data/lib/addressabler.rb +80 -0
- data/lib/tlds +3824 -0
- data/spec/addressabler_spec.rb +46 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/uri_spec.rb +4210 -0
- metadata +107 -0
data/spec/uri_spec.rb
ADDED
@@ -0,0 +1,4210 @@
|
|
1
|
+
require 'addressabler'
|
2
|
+
require "addressable/uri"
|
3
|
+
|
4
|
+
if !"".respond_to?("force_encoding")
|
5
|
+
class String
|
6
|
+
def force_encoding(encoding)
|
7
|
+
@encoding = encoding
|
8
|
+
end
|
9
|
+
|
10
|
+
def encoding
|
11
|
+
@encoding ||= Encoding::ASCII_8BIT
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class Encoding
|
16
|
+
def initialize(name)
|
17
|
+
@name = name
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_s
|
21
|
+
return @name
|
22
|
+
end
|
23
|
+
|
24
|
+
UTF_8 = Encoding.new("UTF-8")
|
25
|
+
ASCII_8BIT = Encoding.new("US-ASCII")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
module URI
|
30
|
+
class HTTP
|
31
|
+
def initialize(uri)
|
32
|
+
@uri = uri
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_s
|
36
|
+
return @uri.to_s
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe Addressable::URI, "when created with a non-numeric port number" do
|
42
|
+
it "should raise an error" do
|
43
|
+
(lambda do
|
44
|
+
Addressable::URI.new(:port => "bogus")
|
45
|
+
end).should raise_error(Addressable::URI::InvalidURIError)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe Addressable::URI, "when created with a non-string scheme" do
|
50
|
+
it "should raise an error" do
|
51
|
+
(lambda do
|
52
|
+
Addressable::URI.new(:scheme => :bogus)
|
53
|
+
end).should raise_error(TypeError)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe Addressable::URI, "when created with a non-string user" do
|
58
|
+
it "should raise an error" do
|
59
|
+
(lambda do
|
60
|
+
Addressable::URI.new(:user => :bogus)
|
61
|
+
end).should raise_error(TypeError)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe Addressable::URI, "when created with a non-string password" do
|
66
|
+
it "should raise an error" do
|
67
|
+
(lambda do
|
68
|
+
Addressable::URI.new(:password => :bogus)
|
69
|
+
end).should raise_error(TypeError)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe Addressable::URI, "when created with a non-string userinfo" do
|
74
|
+
it "should raise an error" do
|
75
|
+
(lambda do
|
76
|
+
Addressable::URI.new(:userinfo => :bogus)
|
77
|
+
end).should raise_error(TypeError)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe Addressable::URI, "when created with a non-string host" do
|
82
|
+
it "should raise an error" do
|
83
|
+
(lambda do
|
84
|
+
Addressable::URI.new(:host => :bogus)
|
85
|
+
end).should raise_error(TypeError)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe Addressable::URI, "when created with a non-string authority" do
|
90
|
+
it "should raise an error" do
|
91
|
+
(lambda do
|
92
|
+
Addressable::URI.new(:authority => :bogus)
|
93
|
+
end).should raise_error(TypeError)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe Addressable::URI, "when created with a non-string authority" do
|
98
|
+
it "should raise an error" do
|
99
|
+
(lambda do
|
100
|
+
Addressable::URI.new(:authority => :bogus)
|
101
|
+
end).should raise_error(TypeError)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe Addressable::URI, "when created with a non-string path" do
|
106
|
+
it "should raise an error" do
|
107
|
+
(lambda do
|
108
|
+
Addressable::URI.new(:path => :bogus)
|
109
|
+
end).should raise_error(TypeError)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe Addressable::URI, "when created with a non-string query" do
|
114
|
+
it "should raise an error" do
|
115
|
+
(lambda do
|
116
|
+
Addressable::URI.new(:query => :bogus)
|
117
|
+
end).should raise_error(TypeError)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe Addressable::URI, "when created with a non-string fragment" do
|
122
|
+
it "should raise an error" do
|
123
|
+
(lambda do
|
124
|
+
Addressable::URI.new(:fragment => :bogus)
|
125
|
+
end).should raise_error(TypeError)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe Addressable::URI, "when created with a scheme but no hierarchical " +
|
130
|
+
"segment" do
|
131
|
+
it "should raise an error" do
|
132
|
+
(lambda do
|
133
|
+
Addressable::URI.parse("http:")
|
134
|
+
end).should raise_error(Addressable::URI::InvalidURIError)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
describe Addressable::URI, "when created from nil components" do
|
139
|
+
before do
|
140
|
+
@uri = Addressable::URI.new
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should have a nil site value" do
|
144
|
+
@uri.site.should == nil
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should have an empty path" do
|
148
|
+
@uri.path.should == ""
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should be an empty uri" do
|
152
|
+
@uri.to_s.should == ""
|
153
|
+
end
|
154
|
+
|
155
|
+
it "should raise an error if the scheme is set to whitespace" do
|
156
|
+
(lambda do
|
157
|
+
@uri.scheme = "\t \n"
|
158
|
+
end).should raise_error(Addressable::URI::InvalidURIError)
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should raise an error if the scheme is set to all digits" do
|
162
|
+
(lambda do
|
163
|
+
@uri.scheme = "123"
|
164
|
+
end).should raise_error(Addressable::URI::InvalidURIError)
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should raise an error if set into an invalid state" do
|
168
|
+
(lambda do
|
169
|
+
@uri.user = "user"
|
170
|
+
end).should raise_error(Addressable::URI::InvalidURIError)
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should raise an error if set into an invalid state" do
|
174
|
+
(lambda do
|
175
|
+
@uri.password = "pass"
|
176
|
+
end).should raise_error(Addressable::URI::InvalidURIError)
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should raise an error if set into an invalid state" do
|
180
|
+
(lambda do
|
181
|
+
@uri.scheme = "http"
|
182
|
+
@uri.fragment = "fragment"
|
183
|
+
end).should raise_error(Addressable::URI::InvalidURIError)
|
184
|
+
end
|
185
|
+
|
186
|
+
it "should raise an error if set into an invalid state" do
|
187
|
+
(lambda do
|
188
|
+
@uri.fragment = "fragment"
|
189
|
+
@uri.scheme = "http"
|
190
|
+
end).should raise_error(Addressable::URI::InvalidURIError)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
describe Addressable::URI, "when created from string components" do
|
195
|
+
before do
|
196
|
+
@uri = Addressable::URI.new(
|
197
|
+
:scheme => "http", :host => "example.com"
|
198
|
+
)
|
199
|
+
end
|
200
|
+
|
201
|
+
it "should have a site value of 'http://example.com'" do
|
202
|
+
@uri.site.should == "http://example.com"
|
203
|
+
end
|
204
|
+
|
205
|
+
it "should be equal to the equivalent parsed URI" do
|
206
|
+
@uri.should == Addressable::URI.parse("http://example.com")
|
207
|
+
end
|
208
|
+
|
209
|
+
it "should raise an error if invalid components omitted" do
|
210
|
+
(lambda do
|
211
|
+
@uri.omit(:bogus)
|
212
|
+
end).should raise_error(ArgumentError)
|
213
|
+
(lambda do
|
214
|
+
@uri.omit(:scheme, :bogus, :path)
|
215
|
+
end).should raise_error(ArgumentError)
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
describe Addressable::URI, "when created with a nil host but " +
|
220
|
+
"non-nil authority components" do
|
221
|
+
it "should raise an error" do
|
222
|
+
(lambda do
|
223
|
+
Addressable::URI.new(:user => "user", :password => "pass", :port => 80)
|
224
|
+
end).should raise_error(Addressable::URI::InvalidURIError)
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
describe Addressable::URI, "when created with both an authority and a user" do
|
229
|
+
it "should raise an error" do
|
230
|
+
(lambda do
|
231
|
+
Addressable::URI.new(
|
232
|
+
:user => "user", :authority => "user@example.com:80"
|
233
|
+
)
|
234
|
+
end).should raise_error(ArgumentError)
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
describe Addressable::URI, "when created with an authority and no port" do
|
239
|
+
before do
|
240
|
+
@uri = Addressable::URI.new(:authority => "user@example.com")
|
241
|
+
end
|
242
|
+
|
243
|
+
it "should not infer a port" do
|
244
|
+
@uri.port.should == nil
|
245
|
+
@uri.inferred_port.should == nil
|
246
|
+
end
|
247
|
+
|
248
|
+
it "should have a site value of '//user@example.com'" do
|
249
|
+
@uri.site.should == "//user@example.com"
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
describe Addressable::URI, "when created with both a userinfo and a user" do
|
254
|
+
it "should raise an error" do
|
255
|
+
(lambda do
|
256
|
+
Addressable::URI.new(:user => "user", :userinfo => "user:pass")
|
257
|
+
end).should raise_error(ArgumentError)
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
describe Addressable::URI, "when created with a path that hasn't been " +
|
262
|
+
"prefixed with a '/' but a host specified" do
|
263
|
+
before do
|
264
|
+
@uri = Addressable::URI.new(
|
265
|
+
:scheme => "http", :host => "example.com", :path => "path"
|
266
|
+
)
|
267
|
+
end
|
268
|
+
|
269
|
+
it "should prefix a '/' to the path" do
|
270
|
+
@uri.should == Addressable::URI.parse("http://example.com/path")
|
271
|
+
end
|
272
|
+
|
273
|
+
it "should have a site value of 'http://example.com'" do
|
274
|
+
@uri.site.should == "http://example.com"
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
describe Addressable::URI, "when created with a path that hasn't been " +
|
279
|
+
"prefixed with a '/' but no host specified" do
|
280
|
+
before do
|
281
|
+
@uri = Addressable::URI.new(
|
282
|
+
:scheme => "http", :path => "path"
|
283
|
+
)
|
284
|
+
end
|
285
|
+
|
286
|
+
it "should not prefix a '/' to the path" do
|
287
|
+
@uri.should == Addressable::URI.parse("http:path")
|
288
|
+
end
|
289
|
+
|
290
|
+
it "should have a site value of 'http:'" do
|
291
|
+
@uri.site.should == "http:"
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
describe Addressable::URI, "when parsed from an Addressable::URI object" do
|
296
|
+
it "should return the object" do
|
297
|
+
uri = Addressable::URI.parse("http://example.com/")
|
298
|
+
(lambda do
|
299
|
+
Addressable::URI.parse(uri).object_id.should == uri.object_id
|
300
|
+
end).should_not raise_error
|
301
|
+
end
|
302
|
+
|
303
|
+
it "should return the object" do
|
304
|
+
uri = Addressable::URI.parse("http://example.com/")
|
305
|
+
(lambda do
|
306
|
+
Addressable::URI.heuristic_parse(uri).object_id.should == uri.object_id
|
307
|
+
end).should_not raise_error
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
describe Addressable::URI, "when parsed from something that looks " +
|
312
|
+
"like a URI object" do
|
313
|
+
it "should parse without error" do
|
314
|
+
uri = Addressable::URI.parse(URI::HTTP.new("http://example.com/"))
|
315
|
+
(lambda do
|
316
|
+
Addressable::URI.parse(uri)
|
317
|
+
end).should_not raise_error
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
describe Addressable::URI, "when parsed from ''" do
|
322
|
+
before do
|
323
|
+
@uri = Addressable::URI.parse("")
|
324
|
+
end
|
325
|
+
|
326
|
+
it "should have no scheme" do
|
327
|
+
@uri.scheme.should == nil
|
328
|
+
end
|
329
|
+
|
330
|
+
it "should not be considered to be ip-based" do
|
331
|
+
@uri.should_not be_ip_based
|
332
|
+
end
|
333
|
+
|
334
|
+
it "should have a path of ''" do
|
335
|
+
@uri.path.should == ""
|
336
|
+
end
|
337
|
+
|
338
|
+
it "should have a request URI of '/'" do
|
339
|
+
@uri.request_uri.should == "/"
|
340
|
+
end
|
341
|
+
|
342
|
+
it "should be considered relative" do
|
343
|
+
@uri.should be_relative
|
344
|
+
end
|
345
|
+
|
346
|
+
it "should be considered to be in normal form" do
|
347
|
+
@uri.normalize.should be_eql(@uri)
|
348
|
+
end
|
349
|
+
end
|
350
|
+
|
351
|
+
# Section 1.1.2 of RFC 3986
|
352
|
+
describe Addressable::URI, "when parsed from " +
|
353
|
+
"'ftp://ftp.is.co.za/rfc/rfc1808.txt'" do
|
354
|
+
before do
|
355
|
+
@uri = Addressable::URI.parse("ftp://ftp.is.co.za/rfc/rfc1808.txt")
|
356
|
+
end
|
357
|
+
|
358
|
+
it "should use the 'ftp' scheme" do
|
359
|
+
@uri.scheme.should == "ftp"
|
360
|
+
end
|
361
|
+
|
362
|
+
it "should be considered to be ip-based" do
|
363
|
+
@uri.should be_ip_based
|
364
|
+
end
|
365
|
+
|
366
|
+
it "should have a host of 'ftp.is.co.za'" do
|
367
|
+
@uri.host.should == "ftp.is.co.za"
|
368
|
+
end
|
369
|
+
|
370
|
+
it "should have a path of '/rfc/rfc1808.txt'" do
|
371
|
+
@uri.path.should == "/rfc/rfc1808.txt"
|
372
|
+
end
|
373
|
+
|
374
|
+
it "should not have a request URI" do
|
375
|
+
@uri.request_uri.should == nil
|
376
|
+
end
|
377
|
+
|
378
|
+
it "should be considered to be in normal form" do
|
379
|
+
@uri.normalize.should be_eql(@uri)
|
380
|
+
end
|
381
|
+
end
|
382
|
+
|
383
|
+
# Section 1.1.2 of RFC 3986
|
384
|
+
describe Addressable::URI, "when parsed from " +
|
385
|
+
"'http://www.ietf.org/rfc/rfc2396.txt'" do
|
386
|
+
before do
|
387
|
+
@uri = Addressable::URI.parse("http://www.ietf.org/rfc/rfc2396.txt")
|
388
|
+
end
|
389
|
+
|
390
|
+
it "should use the 'http' scheme" do
|
391
|
+
@uri.scheme.should == "http"
|
392
|
+
end
|
393
|
+
|
394
|
+
it "should be considered to be ip-based" do
|
395
|
+
@uri.should be_ip_based
|
396
|
+
end
|
397
|
+
|
398
|
+
it "should have a host of 'www.ietf.org'" do
|
399
|
+
@uri.host.should == "www.ietf.org"
|
400
|
+
end
|
401
|
+
|
402
|
+
it "should have a path of '/rfc/rfc2396.txt'" do
|
403
|
+
@uri.path.should == "/rfc/rfc2396.txt"
|
404
|
+
end
|
405
|
+
|
406
|
+
it "should have a request URI of '/rfc/rfc2396.txt'" do
|
407
|
+
@uri.request_uri.should == "/rfc/rfc2396.txt"
|
408
|
+
end
|
409
|
+
|
410
|
+
it "should be considered to be in normal form" do
|
411
|
+
@uri.normalize.should be_eql(@uri)
|
412
|
+
end
|
413
|
+
|
414
|
+
it "should correctly omit components" do
|
415
|
+
@uri.omit(:scheme).to_s.should == "//www.ietf.org/rfc/rfc2396.txt"
|
416
|
+
@uri.omit(:path).to_s.should == "http://www.ietf.org"
|
417
|
+
end
|
418
|
+
|
419
|
+
it "should correctly omit components destructively" do
|
420
|
+
@uri.omit!(:scheme)
|
421
|
+
@uri.to_s.should == "//www.ietf.org/rfc/rfc2396.txt"
|
422
|
+
end
|
423
|
+
end
|
424
|
+
|
425
|
+
# Section 1.1.2 of RFC 3986
|
426
|
+
describe Addressable::URI, "when parsed from " +
|
427
|
+
"'ldap://[2001:db8::7]/c=GB?objectClass?one'" do
|
428
|
+
before do
|
429
|
+
@uri = Addressable::URI.parse("ldap://[2001:db8::7]/c=GB?objectClass?one")
|
430
|
+
end
|
431
|
+
|
432
|
+
it "should use the 'ldap' scheme" do
|
433
|
+
@uri.scheme.should == "ldap"
|
434
|
+
end
|
435
|
+
|
436
|
+
it "should be considered to be ip-based" do
|
437
|
+
@uri.should be_ip_based
|
438
|
+
end
|
439
|
+
|
440
|
+
it "should have a host of '[2001:db8::7]'" do
|
441
|
+
@uri.host.should == "[2001:db8::7]"
|
442
|
+
end
|
443
|
+
|
444
|
+
it "should have a path of '/c=GB'" do
|
445
|
+
@uri.path.should == "/c=GB"
|
446
|
+
end
|
447
|
+
|
448
|
+
it "should not have a request URI" do
|
449
|
+
@uri.request_uri.should == nil
|
450
|
+
end
|
451
|
+
|
452
|
+
it "should not allow request URI assignment" do
|
453
|
+
(lambda do
|
454
|
+
@uri.request_uri = "/"
|
455
|
+
end).should raise_error(Addressable::URI::InvalidURIError)
|
456
|
+
end
|
457
|
+
|
458
|
+
it "should have a query of 'objectClass?one'" do
|
459
|
+
@uri.query.should == "objectClass?one"
|
460
|
+
end
|
461
|
+
|
462
|
+
it "should be considered to be in normal form" do
|
463
|
+
@uri.normalize.should be_eql(@uri)
|
464
|
+
end
|
465
|
+
|
466
|
+
it "should correctly omit components" do
|
467
|
+
@uri.omit(:scheme, :authority).to_s.should == "/c=GB?objectClass?one"
|
468
|
+
@uri.omit(:path).to_s.should == "ldap://[2001:db8::7]?objectClass?one"
|
469
|
+
end
|
470
|
+
|
471
|
+
it "should correctly omit components destructively" do
|
472
|
+
@uri.omit!(:scheme, :authority)
|
473
|
+
@uri.to_s.should == "/c=GB?objectClass?one"
|
474
|
+
end
|
475
|
+
|
476
|
+
it "should raise an error if omission would create an invalid URI" do
|
477
|
+
(lambda do
|
478
|
+
@uri.omit(:authority, :path)
|
479
|
+
end).should raise_error(Addressable::URI::InvalidURIError)
|
480
|
+
end
|
481
|
+
end
|
482
|
+
|
483
|
+
# Section 1.1.2 of RFC 3986
|
484
|
+
describe Addressable::URI, "when parsed from " +
|
485
|
+
"'mailto:John.Doe@example.com'" do
|
486
|
+
before do
|
487
|
+
@uri = Addressable::URI.parse("mailto:John.Doe@example.com")
|
488
|
+
end
|
489
|
+
|
490
|
+
it "should use the 'mailto' scheme" do
|
491
|
+
@uri.scheme.should == "mailto"
|
492
|
+
end
|
493
|
+
|
494
|
+
it "should not be considered to be ip-based" do
|
495
|
+
@uri.should_not be_ip_based
|
496
|
+
end
|
497
|
+
|
498
|
+
it "should have a path of 'John.Doe@example.com'" do
|
499
|
+
@uri.path.should == "John.Doe@example.com"
|
500
|
+
end
|
501
|
+
|
502
|
+
it "should not have a request URI" do
|
503
|
+
@uri.request_uri.should == nil
|
504
|
+
end
|
505
|
+
|
506
|
+
it "should be considered to be in normal form" do
|
507
|
+
@uri.normalize.should be_eql(@uri)
|
508
|
+
end
|
509
|
+
end
|
510
|
+
|
511
|
+
# Section 1.1.2 of RFC 3986
|
512
|
+
describe Addressable::URI, "when parsed from " +
|
513
|
+
"'news:comp.infosystems.www.servers.unix'" do
|
514
|
+
before do
|
515
|
+
@uri = Addressable::URI.parse("news:comp.infosystems.www.servers.unix")
|
516
|
+
end
|
517
|
+
|
518
|
+
it "should use the 'news' scheme" do
|
519
|
+
@uri.scheme.should == "news"
|
520
|
+
end
|
521
|
+
|
522
|
+
it "should not be considered to be ip-based" do
|
523
|
+
@uri.should_not be_ip_based
|
524
|
+
end
|
525
|
+
|
526
|
+
it "should have a path of 'comp.infosystems.www.servers.unix'" do
|
527
|
+
@uri.path.should == "comp.infosystems.www.servers.unix"
|
528
|
+
end
|
529
|
+
|
530
|
+
it "should not have a request URI" do
|
531
|
+
@uri.request_uri.should == nil
|
532
|
+
end
|
533
|
+
|
534
|
+
it "should be considered to be in normal form" do
|
535
|
+
@uri.normalize.should be_eql(@uri)
|
536
|
+
end
|
537
|
+
end
|
538
|
+
|
539
|
+
# Section 1.1.2 of RFC 3986
|
540
|
+
describe Addressable::URI, "when parsed from " +
|
541
|
+
"'tel:+1-816-555-1212'" do
|
542
|
+
before do
|
543
|
+
@uri = Addressable::URI.parse("tel:+1-816-555-1212")
|
544
|
+
end
|
545
|
+
|
546
|
+
it "should use the 'tel' scheme" do
|
547
|
+
@uri.scheme.should == "tel"
|
548
|
+
end
|
549
|
+
|
550
|
+
it "should not be considered to be ip-based" do
|
551
|
+
@uri.should_not be_ip_based
|
552
|
+
end
|
553
|
+
|
554
|
+
it "should have a path of '+1-816-555-1212'" do
|
555
|
+
@uri.path.should == "+1-816-555-1212"
|
556
|
+
end
|
557
|
+
|
558
|
+
it "should not have a request URI" do
|
559
|
+
@uri.request_uri.should == nil
|
560
|
+
end
|
561
|
+
|
562
|
+
it "should be considered to be in normal form" do
|
563
|
+
@uri.normalize.should be_eql(@uri)
|
564
|
+
end
|
565
|
+
end
|
566
|
+
|
567
|
+
# Section 1.1.2 of RFC 3986
|
568
|
+
describe Addressable::URI, "when parsed from " +
|
569
|
+
"'telnet://192.0.2.16:80/'" do
|
570
|
+
before do
|
571
|
+
@uri = Addressable::URI.parse("telnet://192.0.2.16:80/")
|
572
|
+
end
|
573
|
+
|
574
|
+
it "should use the 'telnet' scheme" do
|
575
|
+
@uri.scheme.should == "telnet"
|
576
|
+
end
|
577
|
+
|
578
|
+
it "should have a host of '192.0.2.16'" do
|
579
|
+
@uri.host.should == "192.0.2.16"
|
580
|
+
end
|
581
|
+
|
582
|
+
it "should have a port of '80'" do
|
583
|
+
@uri.port.should == 80
|
584
|
+
end
|
585
|
+
|
586
|
+
it "should be considered to be ip-based" do
|
587
|
+
@uri.should be_ip_based
|
588
|
+
end
|
589
|
+
|
590
|
+
it "should have a path of '/'" do
|
591
|
+
@uri.path.should == "/"
|
592
|
+
end
|
593
|
+
|
594
|
+
it "should not have a request URI" do
|
595
|
+
@uri.request_uri.should == nil
|
596
|
+
end
|
597
|
+
|
598
|
+
it "should be considered to be in normal form" do
|
599
|
+
@uri.normalize.should be_eql(@uri)
|
600
|
+
end
|
601
|
+
end
|
602
|
+
|
603
|
+
# Section 1.1.2 of RFC 3986
|
604
|
+
describe Addressable::URI, "when parsed from " +
|
605
|
+
"'urn:oasis:names:specification:docbook:dtd:xml:4.1.2'" do
|
606
|
+
before do
|
607
|
+
@uri = Addressable::URI.parse(
|
608
|
+
"urn:oasis:names:specification:docbook:dtd:xml:4.1.2")
|
609
|
+
end
|
610
|
+
|
611
|
+
it "should use the 'urn' scheme" do
|
612
|
+
@uri.scheme.should == "urn"
|
613
|
+
end
|
614
|
+
|
615
|
+
it "should not be considered to be ip-based" do
|
616
|
+
@uri.should_not be_ip_based
|
617
|
+
end
|
618
|
+
|
619
|
+
it "should have a path of " +
|
620
|
+
"'oasis:names:specification:docbook:dtd:xml:4.1.2'" do
|
621
|
+
@uri.path.should == "oasis:names:specification:docbook:dtd:xml:4.1.2"
|
622
|
+
end
|
623
|
+
|
624
|
+
it "should not have a request URI" do
|
625
|
+
@uri.request_uri.should == nil
|
626
|
+
end
|
627
|
+
|
628
|
+
it "should be considered to be in normal form" do
|
629
|
+
@uri.normalize.should be_eql(@uri)
|
630
|
+
end
|
631
|
+
end
|
632
|
+
|
633
|
+
describe Addressable::URI, "when parsed from " +
|
634
|
+
"'http://example.com'" do
|
635
|
+
before do
|
636
|
+
@uri = Addressable::URI.parse("http://example.com")
|
637
|
+
end
|
638
|
+
|
639
|
+
it "when inspected, should have the correct URI" do
|
640
|
+
@uri.inspect.should include("http://example.com")
|
641
|
+
end
|
642
|
+
|
643
|
+
it "when inspected, should have the correct class name" do
|
644
|
+
@uri.inspect.should include("Addressable::URI")
|
645
|
+
end
|
646
|
+
|
647
|
+
it "when inspected, should have the correct object id" do
|
648
|
+
@uri.inspect.should include("%#0x" % @uri.object_id)
|
649
|
+
end
|
650
|
+
|
651
|
+
it "should use the 'http' scheme" do
|
652
|
+
@uri.scheme.should == "http"
|
653
|
+
end
|
654
|
+
|
655
|
+
it "should be considered to be ip-based" do
|
656
|
+
@uri.should be_ip_based
|
657
|
+
end
|
658
|
+
|
659
|
+
it "should have an authority segment of 'example.com'" do
|
660
|
+
@uri.authority.should == "example.com"
|
661
|
+
end
|
662
|
+
|
663
|
+
it "should have a host of 'example.com'" do
|
664
|
+
@uri.host.should == "example.com"
|
665
|
+
end
|
666
|
+
|
667
|
+
it "should be considered ip-based" do
|
668
|
+
@uri.should be_ip_based
|
669
|
+
end
|
670
|
+
|
671
|
+
it "should have no username" do
|
672
|
+
@uri.user.should == nil
|
673
|
+
end
|
674
|
+
|
675
|
+
it "should have no password" do
|
676
|
+
@uri.password.should == nil
|
677
|
+
end
|
678
|
+
|
679
|
+
it "should use port 80" do
|
680
|
+
@uri.inferred_port.should == 80
|
681
|
+
end
|
682
|
+
|
683
|
+
it "should not have a specified port" do
|
684
|
+
@uri.port.should == nil
|
685
|
+
end
|
686
|
+
|
687
|
+
it "should have an empty path" do
|
688
|
+
@uri.path.should == ""
|
689
|
+
end
|
690
|
+
|
691
|
+
it "should have no query string" do
|
692
|
+
@uri.query.should == nil
|
693
|
+
@uri.query_values.should == nil
|
694
|
+
end
|
695
|
+
|
696
|
+
it "should have a request URI of '/'" do
|
697
|
+
@uri.request_uri.should == "/"
|
698
|
+
end
|
699
|
+
|
700
|
+
it "should have no fragment" do
|
701
|
+
@uri.fragment.should == nil
|
702
|
+
end
|
703
|
+
|
704
|
+
it "should be considered absolute" do
|
705
|
+
@uri.should be_absolute
|
706
|
+
end
|
707
|
+
|
708
|
+
it "should not be considered relative" do
|
709
|
+
@uri.should_not be_relative
|
710
|
+
end
|
711
|
+
|
712
|
+
it "should not be exactly equal to 42" do
|
713
|
+
@uri.eql?(42).should == false
|
714
|
+
end
|
715
|
+
|
716
|
+
it "should not be equal to 42" do
|
717
|
+
(@uri == 42).should == false
|
718
|
+
end
|
719
|
+
|
720
|
+
it "should not be roughly equal to 42" do
|
721
|
+
(@uri === 42).should == false
|
722
|
+
end
|
723
|
+
|
724
|
+
it "should be exactly equal to http://example.com" do
|
725
|
+
@uri.eql?(Addressable::URI.parse("http://example.com")).should == true
|
726
|
+
end
|
727
|
+
|
728
|
+
it "should be roughly equal to http://example.com/" do
|
729
|
+
(@uri === Addressable::URI.parse("http://example.com/")).should == true
|
730
|
+
end
|
731
|
+
|
732
|
+
it "should be roughly equal to the string 'http://example.com/'" do
|
733
|
+
(@uri === "http://example.com/").should == true
|
734
|
+
end
|
735
|
+
|
736
|
+
it "should not be roughly equal to the string " +
|
737
|
+
"'http://example.com:bogus/'" do
|
738
|
+
(lambda do
|
739
|
+
(@uri === "http://example.com:bogus/").should == false
|
740
|
+
end).should_not raise_error
|
741
|
+
end
|
742
|
+
|
743
|
+
it "should result in itself when joined with itself" do
|
744
|
+
@uri.join(@uri).to_s.should == "http://example.com"
|
745
|
+
@uri.join!(@uri).to_s.should == "http://example.com"
|
746
|
+
end
|
747
|
+
|
748
|
+
it "should be equivalent to http://EXAMPLE.com" do
|
749
|
+
@uri.should == Addressable::URI.parse("http://EXAMPLE.com")
|
750
|
+
end
|
751
|
+
|
752
|
+
it "should be equivalent to http://EXAMPLE.com:80/" do
|
753
|
+
@uri.should == Addressable::URI.parse("http://EXAMPLE.com:80/")
|
754
|
+
end
|
755
|
+
|
756
|
+
it "should have the same hash as http://example.com" do
|
757
|
+
@uri.hash.should == Addressable::URI.parse("http://example.com").hash
|
758
|
+
end
|
759
|
+
|
760
|
+
it "should have the same hash as http://EXAMPLE.com after assignment" do
|
761
|
+
@uri.host = "EXAMPLE.com"
|
762
|
+
@uri.hash.should == Addressable::URI.parse("http://EXAMPLE.com").hash
|
763
|
+
end
|
764
|
+
|
765
|
+
it "should have a different hash from http://EXAMPLE.com" do
|
766
|
+
@uri.hash.should_not == Addressable::URI.parse("http://EXAMPLE.com").hash
|
767
|
+
end
|
768
|
+
|
769
|
+
# Section 6.2.3 of RFC 3986
|
770
|
+
it "should be equivalent to http://example.com/" do
|
771
|
+
@uri.should == Addressable::URI.parse("http://example.com/")
|
772
|
+
end
|
773
|
+
|
774
|
+
# Section 6.2.3 of RFC 3986
|
775
|
+
it "should be equivalent to http://example.com:/" do
|
776
|
+
@uri.should == Addressable::URI.parse("http://example.com:/")
|
777
|
+
end
|
778
|
+
|
779
|
+
# Section 6.2.3 of RFC 3986
|
780
|
+
it "should be equivalent to http://example.com:80/" do
|
781
|
+
@uri.should == Addressable::URI.parse("http://example.com:80/")
|
782
|
+
end
|
783
|
+
|
784
|
+
# Section 6.2.2.1 of RFC 3986
|
785
|
+
it "should be equivalent to http://EXAMPLE.COM/" do
|
786
|
+
@uri.should == Addressable::URI.parse("http://EXAMPLE.COM/")
|
787
|
+
end
|
788
|
+
|
789
|
+
it "should have a route of '/path/' to 'http://example.com/path/'" do
|
790
|
+
@uri.route_to("http://example.com/path/").should ==
|
791
|
+
Addressable::URI.parse("/path/")
|
792
|
+
end
|
793
|
+
|
794
|
+
it "should have a route of '/' from 'http://example.com/path/'" do
|
795
|
+
@uri.route_from("http://example.com/path/").should ==
|
796
|
+
Addressable::URI.parse("/")
|
797
|
+
end
|
798
|
+
|
799
|
+
it "should have a route of '#' to 'http://example.com/'" do
|
800
|
+
@uri.route_to("http://example.com/").should ==
|
801
|
+
Addressable::URI.parse("#")
|
802
|
+
end
|
803
|
+
|
804
|
+
it "should have a route of 'http://elsewhere.com/' to " +
|
805
|
+
"'http://elsewhere.com/'" do
|
806
|
+
@uri.route_to("http://elsewhere.com/").should ==
|
807
|
+
Addressable::URI.parse("http://elsewhere.com/")
|
808
|
+
end
|
809
|
+
|
810
|
+
it "when joined with 'relative/path' should be " +
|
811
|
+
"'http://example.com/relative/path'" do
|
812
|
+
@uri.join('relative/path').should ==
|
813
|
+
Addressable::URI.parse("http://example.com/relative/path")
|
814
|
+
end
|
815
|
+
|
816
|
+
it "when joined with a bogus object a TypeError should be raised" do
|
817
|
+
(lambda do
|
818
|
+
@uri.join(42)
|
819
|
+
end).should raise_error(TypeError)
|
820
|
+
end
|
821
|
+
|
822
|
+
it "should have the correct username after assignment" do
|
823
|
+
@uri.user = "newuser"
|
824
|
+
@uri.user.should == "newuser"
|
825
|
+
@uri.password.should == nil
|
826
|
+
@uri.to_s.should == "http://newuser@example.com"
|
827
|
+
end
|
828
|
+
|
829
|
+
it "should have the correct username after assignment" do
|
830
|
+
@uri.user = "user@123!"
|
831
|
+
@uri.user.should == "user@123!"
|
832
|
+
@uri.normalized_user.should == "user%40123%21"
|
833
|
+
@uri.password.should == nil
|
834
|
+
@uri.normalize.to_s.should == "http://user%40123%21@example.com/"
|
835
|
+
end
|
836
|
+
|
837
|
+
it "should have the correct password after assignment" do
|
838
|
+
@uri.password = "newpass"
|
839
|
+
@uri.password.should == "newpass"
|
840
|
+
@uri.user.should == ""
|
841
|
+
@uri.to_s.should == "http://:newpass@example.com"
|
842
|
+
end
|
843
|
+
|
844
|
+
it "should have the correct password after assignment" do
|
845
|
+
@uri.password = "secret@123!"
|
846
|
+
@uri.password.should == "secret@123!"
|
847
|
+
@uri.normalized_password.should == "secret%40123%21"
|
848
|
+
@uri.user.should == ""
|
849
|
+
@uri.normalize.to_s.should == "http://:secret%40123%21@example.com/"
|
850
|
+
@uri.omit(:password).to_s.should == "http://example.com"
|
851
|
+
end
|
852
|
+
|
853
|
+
it "should have the correct user/pass after repeated assignment" do
|
854
|
+
@uri.user = nil
|
855
|
+
@uri.user.should == nil
|
856
|
+
@uri.password = "newpass"
|
857
|
+
@uri.password.should == "newpass"
|
858
|
+
# Username cannot be nil if the password is set
|
859
|
+
@uri.user.should == ""
|
860
|
+
@uri.to_s.should == "http://:newpass@example.com"
|
861
|
+
@uri.user = "newuser"
|
862
|
+
@uri.user.should == "newuser"
|
863
|
+
@uri.password = nil
|
864
|
+
@uri.password.should == nil
|
865
|
+
@uri.to_s.should == "http://newuser@example.com"
|
866
|
+
@uri.user = "newuser"
|
867
|
+
@uri.user.should == "newuser"
|
868
|
+
@uri.password = ""
|
869
|
+
@uri.password.should == ""
|
870
|
+
@uri.to_s.should == "http://newuser:@example.com"
|
871
|
+
@uri.password = "newpass"
|
872
|
+
@uri.password.should == "newpass"
|
873
|
+
@uri.user = nil
|
874
|
+
# Username cannot be nil if the password is set
|
875
|
+
@uri.user.should == ""
|
876
|
+
@uri.to_s.should == "http://:newpass@example.com"
|
877
|
+
end
|
878
|
+
|
879
|
+
it "should have the correct user/pass after userinfo assignment" do
|
880
|
+
@uri.user = "newuser"
|
881
|
+
@uri.user.should == "newuser"
|
882
|
+
@uri.password = "newpass"
|
883
|
+
@uri.password.should == "newpass"
|
884
|
+
@uri.userinfo = nil
|
885
|
+
@uri.userinfo.should == nil
|
886
|
+
@uri.user.should == nil
|
887
|
+
@uri.password.should == nil
|
888
|
+
end
|
889
|
+
|
890
|
+
it "should correctly convert to a hash" do
|
891
|
+
@uri.to_hash.should == {
|
892
|
+
:scheme => "http",
|
893
|
+
:user => nil,
|
894
|
+
:password => nil,
|
895
|
+
:host => "example.com",
|
896
|
+
:port => nil,
|
897
|
+
:path => "",
|
898
|
+
:query => nil,
|
899
|
+
:fragment => nil
|
900
|
+
}
|
901
|
+
end
|
902
|
+
|
903
|
+
it "should be identical to its duplicate" do
|
904
|
+
@uri.should == @uri.dup
|
905
|
+
end
|
906
|
+
end
|
907
|
+
|
908
|
+
# Section 5.1.2 of RFC 2616
|
909
|
+
describe Addressable::URI, "when parsed from " +
|
910
|
+
"'http://www.w3.org/pub/WWW/TheProject.html'" do
|
911
|
+
before do
|
912
|
+
@uri = Addressable::URI.parse("http://www.w3.org/pub/WWW/TheProject.html")
|
913
|
+
end
|
914
|
+
|
915
|
+
it "should have the correct request URI" do
|
916
|
+
@uri.request_uri.should == "/pub/WWW/TheProject.html"
|
917
|
+
end
|
918
|
+
|
919
|
+
it "should have the correct request URI after assignment" do
|
920
|
+
@uri.request_uri = "/some/where/else.html?query?string"
|
921
|
+
@uri.request_uri.should == "/some/where/else.html?query?string"
|
922
|
+
@uri.path.should == "/some/where/else.html"
|
923
|
+
@uri.query.should == "query?string"
|
924
|
+
end
|
925
|
+
|
926
|
+
it "should have the correct request URI after assignment" do
|
927
|
+
@uri.request_uri = "?x=y"
|
928
|
+
@uri.request_uri.should == "/?x=y"
|
929
|
+
@uri.path.should == "/"
|
930
|
+
@uri.query.should == "x=y"
|
931
|
+
end
|
932
|
+
|
933
|
+
it "should raise an error if the site value is set to something bogus" do
|
934
|
+
(lambda do
|
935
|
+
@uri.site = 42
|
936
|
+
end).should raise_error(TypeError)
|
937
|
+
end
|
938
|
+
|
939
|
+
it "should raise an error if the request URI is set to something bogus" do
|
940
|
+
(lambda do
|
941
|
+
@uri.request_uri = 42
|
942
|
+
end).should raise_error(TypeError)
|
943
|
+
end
|
944
|
+
|
945
|
+
it "should correctly convert to a hash" do
|
946
|
+
@uri.to_hash.should == {
|
947
|
+
:scheme => "http",
|
948
|
+
:user => nil,
|
949
|
+
:password => nil,
|
950
|
+
:host => "www.w3.org",
|
951
|
+
:port => nil,
|
952
|
+
:path => "/pub/WWW/TheProject.html",
|
953
|
+
:query => nil,
|
954
|
+
:fragment => nil
|
955
|
+
}
|
956
|
+
end
|
957
|
+
end
|
958
|
+
|
959
|
+
describe Addressable::URI, "when parsed from " +
|
960
|
+
"'http://example.com/'" do
|
961
|
+
before do
|
962
|
+
@uri = Addressable::URI.parse("http://example.com/")
|
963
|
+
end
|
964
|
+
|
965
|
+
# Based on http://intertwingly.net/blog/2004/07/31/URI-Equivalence
|
966
|
+
it "should be equivalent to http://example.com" do
|
967
|
+
@uri.should == Addressable::URI.parse("http://example.com")
|
968
|
+
end
|
969
|
+
|
970
|
+
# Based on http://intertwingly.net/blog/2004/07/31/URI-Equivalence
|
971
|
+
it "should be equivalent to HTTP://example.com/" do
|
972
|
+
@uri.should == Addressable::URI.parse("HTTP://example.com/")
|
973
|
+
end
|
974
|
+
|
975
|
+
# Based on http://intertwingly.net/blog/2004/07/31/URI-Equivalence
|
976
|
+
it "should be equivalent to http://example.com:/" do
|
977
|
+
@uri.should == Addressable::URI.parse("http://example.com:/")
|
978
|
+
end
|
979
|
+
|
980
|
+
# Based on http://intertwingly.net/blog/2004/07/31/URI-Equivalence
|
981
|
+
it "should be equivalent to http://example.com:80/" do
|
982
|
+
@uri.should == Addressable::URI.parse("http://example.com:80/")
|
983
|
+
end
|
984
|
+
|
985
|
+
# Based on http://intertwingly.net/blog/2004/07/31/URI-Equivalence
|
986
|
+
it "should be equivalent to http://Example.com/" do
|
987
|
+
@uri.should == Addressable::URI.parse("http://Example.com/")
|
988
|
+
end
|
989
|
+
|
990
|
+
it "should have the correct username after assignment" do
|
991
|
+
@uri.user = nil
|
992
|
+
@uri.user.should == nil
|
993
|
+
@uri.password.should == nil
|
994
|
+
@uri.to_s.should == "http://example.com/"
|
995
|
+
end
|
996
|
+
|
997
|
+
it "should have the correct password after assignment" do
|
998
|
+
@uri.password = nil
|
999
|
+
@uri.password.should == nil
|
1000
|
+
@uri.user.should == nil
|
1001
|
+
@uri.to_s.should == "http://example.com/"
|
1002
|
+
end
|
1003
|
+
|
1004
|
+
it "should have a request URI of '/'" do
|
1005
|
+
@uri.request_uri.should == "/"
|
1006
|
+
end
|
1007
|
+
|
1008
|
+
it "should correctly convert to a hash" do
|
1009
|
+
@uri.to_hash.should == {
|
1010
|
+
:scheme => "http",
|
1011
|
+
:user => nil,
|
1012
|
+
:password => nil,
|
1013
|
+
:host => "example.com",
|
1014
|
+
:port => nil,
|
1015
|
+
:path => "/",
|
1016
|
+
:query => nil,
|
1017
|
+
:fragment => nil
|
1018
|
+
}
|
1019
|
+
end
|
1020
|
+
|
1021
|
+
it "should be identical to its duplicate" do
|
1022
|
+
@uri.should == @uri.dup
|
1023
|
+
end
|
1024
|
+
|
1025
|
+
it "should have the same hash as its duplicate" do
|
1026
|
+
@uri.hash.should == @uri.dup.hash
|
1027
|
+
end
|
1028
|
+
|
1029
|
+
it "should have a different hash from its equivalent String value" do
|
1030
|
+
@uri.hash.should_not == @uri.to_s.hash
|
1031
|
+
end
|
1032
|
+
|
1033
|
+
it "should have the same hash as an equal URI" do
|
1034
|
+
@uri.hash.should == Addressable::URI.parse("http://example.com/").hash
|
1035
|
+
end
|
1036
|
+
|
1037
|
+
it "should be equivalent to http://EXAMPLE.com" do
|
1038
|
+
@uri.should == Addressable::URI.parse("http://EXAMPLE.com")
|
1039
|
+
end
|
1040
|
+
|
1041
|
+
it "should be equivalent to http://EXAMPLE.com:80/" do
|
1042
|
+
@uri.should == Addressable::URI.parse("http://EXAMPLE.com:80/")
|
1043
|
+
end
|
1044
|
+
|
1045
|
+
it "should have the same hash as http://example.com/" do
|
1046
|
+
@uri.hash.should == Addressable::URI.parse("http://example.com/").hash
|
1047
|
+
end
|
1048
|
+
|
1049
|
+
it "should have the same hash as http://example.com after assignment" do
|
1050
|
+
@uri.path = ""
|
1051
|
+
@uri.hash.should == Addressable::URI.parse("http://example.com").hash
|
1052
|
+
end
|
1053
|
+
|
1054
|
+
it "should have the same hash as http://example.com/? after assignment" do
|
1055
|
+
@uri.query = ""
|
1056
|
+
@uri.hash.should == Addressable::URI.parse("http://example.com/?").hash
|
1057
|
+
end
|
1058
|
+
|
1059
|
+
it "should have the same hash as http://example.com/? after assignment" do
|
1060
|
+
@uri.query_values = {}
|
1061
|
+
@uri.hash.should == Addressable::URI.parse("http://example.com/?").hash
|
1062
|
+
end
|
1063
|
+
|
1064
|
+
it "should have the same hash as http://example.com/# after assignment" do
|
1065
|
+
@uri.fragment = ""
|
1066
|
+
@uri.hash.should == Addressable::URI.parse("http://example.com/#").hash
|
1067
|
+
end
|
1068
|
+
|
1069
|
+
it "should have a different hash from http://example.com" do
|
1070
|
+
@uri.hash.should_not == Addressable::URI.parse("http://example.com").hash
|
1071
|
+
end
|
1072
|
+
end
|
1073
|
+
|
1074
|
+
describe Addressable::URI, "when parsed from " +
|
1075
|
+
"'http://@example.com/'" do
|
1076
|
+
before do
|
1077
|
+
@uri = Addressable::URI.parse("http://@example.com/")
|
1078
|
+
end
|
1079
|
+
|
1080
|
+
it "should be equivalent to http://example.com" do
|
1081
|
+
@uri.should == Addressable::URI.parse("http://example.com")
|
1082
|
+
end
|
1083
|
+
|
1084
|
+
it "should correctly convert to a hash" do
|
1085
|
+
@uri.to_hash.should == {
|
1086
|
+
:scheme => "http",
|
1087
|
+
:user => "",
|
1088
|
+
:password => nil,
|
1089
|
+
:host => "example.com",
|
1090
|
+
:port => nil,
|
1091
|
+
:path => "/",
|
1092
|
+
:query => nil,
|
1093
|
+
:fragment => nil
|
1094
|
+
}
|
1095
|
+
end
|
1096
|
+
|
1097
|
+
it "should be identical to its duplicate" do
|
1098
|
+
@uri.should == @uri.dup
|
1099
|
+
end
|
1100
|
+
end
|
1101
|
+
|
1102
|
+
describe Addressable::URI, "when parsed from " +
|
1103
|
+
"'http://example.com./'" do
|
1104
|
+
before do
|
1105
|
+
@uri = Addressable::URI.parse("http://example.com./")
|
1106
|
+
end
|
1107
|
+
|
1108
|
+
it "should be equivalent to http://example.com" do
|
1109
|
+
@uri.should == Addressable::URI.parse("http://example.com")
|
1110
|
+
end
|
1111
|
+
|
1112
|
+
it "should not be considered to be in normal form" do
|
1113
|
+
@uri.normalize.should_not be_eql(@uri)
|
1114
|
+
end
|
1115
|
+
|
1116
|
+
it "should be identical to its duplicate" do
|
1117
|
+
@uri.should == @uri.dup
|
1118
|
+
end
|
1119
|
+
end
|
1120
|
+
|
1121
|
+
describe Addressable::URI, "when parsed from " +
|
1122
|
+
"'http://:@example.com/'" do
|
1123
|
+
before do
|
1124
|
+
@uri = Addressable::URI.parse("http://:@example.com/")
|
1125
|
+
end
|
1126
|
+
|
1127
|
+
it "should be equivalent to http://example.com" do
|
1128
|
+
@uri.should == Addressable::URI.parse("http://example.com")
|
1129
|
+
end
|
1130
|
+
|
1131
|
+
it "should correctly convert to a hash" do
|
1132
|
+
@uri.to_hash.should == {
|
1133
|
+
:scheme => "http",
|
1134
|
+
:user => "",
|
1135
|
+
:password => "",
|
1136
|
+
:host => "example.com",
|
1137
|
+
:port => nil,
|
1138
|
+
:path => "/",
|
1139
|
+
:query => nil,
|
1140
|
+
:fragment => nil
|
1141
|
+
}
|
1142
|
+
end
|
1143
|
+
|
1144
|
+
it "should be identical to its duplicate" do
|
1145
|
+
@uri.should == @uri.dup
|
1146
|
+
end
|
1147
|
+
end
|
1148
|
+
|
1149
|
+
describe Addressable::URI, "when parsed from " +
|
1150
|
+
"'http://example.com/~smith/'" do
|
1151
|
+
before do
|
1152
|
+
@uri = Addressable::URI.parse("http://example.com/~smith/")
|
1153
|
+
end
|
1154
|
+
|
1155
|
+
# Based on http://intertwingly.net/blog/2004/07/31/URI-Equivalence
|
1156
|
+
it "should be equivalent to http://example.com/%7Esmith/" do
|
1157
|
+
@uri.should == Addressable::URI.parse("http://example.com/%7Esmith/")
|
1158
|
+
end
|
1159
|
+
|
1160
|
+
# Based on http://intertwingly.net/blog/2004/07/31/URI-Equivalence
|
1161
|
+
it "should be equivalent to http://example.com/%7esmith/" do
|
1162
|
+
@uri.should == Addressable::URI.parse("http://example.com/%7esmith/")
|
1163
|
+
end
|
1164
|
+
|
1165
|
+
it "should be identical to its duplicate" do
|
1166
|
+
@uri.should == @uri.dup
|
1167
|
+
end
|
1168
|
+
end
|
1169
|
+
|
1170
|
+
describe Addressable::URI, "when parsed from " +
|
1171
|
+
"'http://example.com/%E8'" do
|
1172
|
+
before do
|
1173
|
+
@uri = Addressable::URI.parse("http://example.com/%E8")
|
1174
|
+
end
|
1175
|
+
|
1176
|
+
it "should not raise an exception when normalized" do
|
1177
|
+
(lambda do
|
1178
|
+
@uri.normalize
|
1179
|
+
end).should_not raise_error(ArgumentError)
|
1180
|
+
end
|
1181
|
+
|
1182
|
+
it "should be considered to be in normal form" do
|
1183
|
+
@uri.normalize.should be_eql(@uri)
|
1184
|
+
end
|
1185
|
+
|
1186
|
+
it "should not change if encoded with the normalizing algorithm" do
|
1187
|
+
Addressable::URI.normalized_encode(@uri).to_s.should ==
|
1188
|
+
"http://example.com/%E8"
|
1189
|
+
Addressable::URI.normalized_encode(@uri, Addressable::URI).to_s.should ===
|
1190
|
+
"http://example.com/%E8"
|
1191
|
+
end
|
1192
|
+
end
|
1193
|
+
|
1194
|
+
describe Addressable::URI, "when parsed from " +
|
1195
|
+
"'http://example.com/path%2Fsegment/'" do
|
1196
|
+
before do
|
1197
|
+
@uri = Addressable::URI.parse("http://example.com/path%2Fsegment/")
|
1198
|
+
end
|
1199
|
+
|
1200
|
+
it "should be considered to be in normal form" do
|
1201
|
+
@uri.normalize.should be_eql(@uri)
|
1202
|
+
end
|
1203
|
+
|
1204
|
+
it "should be equal to 'http://example.com/path%2Fsegment/'" do
|
1205
|
+
@uri.normalize.should be_eql(
|
1206
|
+
Addressable::URI.parse("http://example.com/path%2Fsegment/")
|
1207
|
+
)
|
1208
|
+
end
|
1209
|
+
|
1210
|
+
it "should not be equal to 'http://example.com/path/segment/'" do
|
1211
|
+
@uri.should_not ==
|
1212
|
+
Addressable::URI.parse("http://example.com/path/segment/")
|
1213
|
+
end
|
1214
|
+
|
1215
|
+
it "should not be equal to 'http://example.com/path/segment/'" do
|
1216
|
+
@uri.normalize.should_not be_eql(
|
1217
|
+
Addressable::URI.parse("http://example.com/path/segment/")
|
1218
|
+
)
|
1219
|
+
end
|
1220
|
+
end
|
1221
|
+
|
1222
|
+
describe Addressable::URI, "when parsed from " +
|
1223
|
+
"'http://example.com/?%F6'" do
|
1224
|
+
before do
|
1225
|
+
@uri = Addressable::URI.parse("http://example.com/?%F6")
|
1226
|
+
end
|
1227
|
+
|
1228
|
+
it "should not raise an exception when normalized" do
|
1229
|
+
(lambda do
|
1230
|
+
@uri.normalize
|
1231
|
+
end).should_not raise_error(ArgumentError)
|
1232
|
+
end
|
1233
|
+
|
1234
|
+
it "should be considered to be in normal form" do
|
1235
|
+
@uri.normalize.should be_eql(@uri)
|
1236
|
+
end
|
1237
|
+
|
1238
|
+
it "should not change if encoded with the normalizing algorithm" do
|
1239
|
+
Addressable::URI.normalized_encode(@uri).to_s.should ==
|
1240
|
+
"http://example.com/?%F6"
|
1241
|
+
Addressable::URI.normalized_encode(@uri, Addressable::URI).to_s.should ===
|
1242
|
+
"http://example.com/?%F6"
|
1243
|
+
end
|
1244
|
+
end
|
1245
|
+
|
1246
|
+
describe Addressable::URI, "when parsed from " +
|
1247
|
+
"'http://example.com/#%F6'" do
|
1248
|
+
before do
|
1249
|
+
@uri = Addressable::URI.parse("http://example.com/#%F6")
|
1250
|
+
end
|
1251
|
+
|
1252
|
+
it "should not raise an exception when normalized" do
|
1253
|
+
(lambda do
|
1254
|
+
@uri.normalize
|
1255
|
+
end).should_not raise_error(ArgumentError)
|
1256
|
+
end
|
1257
|
+
|
1258
|
+
it "should be considered to be in normal form" do
|
1259
|
+
@uri.normalize.should be_eql(@uri)
|
1260
|
+
end
|
1261
|
+
|
1262
|
+
it "should not change if encoded with the normalizing algorithm" do
|
1263
|
+
Addressable::URI.normalized_encode(@uri).to_s.should ==
|
1264
|
+
"http://example.com/#%F6"
|
1265
|
+
Addressable::URI.normalized_encode(@uri, Addressable::URI).to_s.should ===
|
1266
|
+
"http://example.com/#%F6"
|
1267
|
+
end
|
1268
|
+
end
|
1269
|
+
|
1270
|
+
describe Addressable::URI, "when parsed from " +
|
1271
|
+
"'http://example.com/%C3%87'" do
|
1272
|
+
before do
|
1273
|
+
@uri = Addressable::URI.parse("http://example.com/%C3%87")
|
1274
|
+
end
|
1275
|
+
|
1276
|
+
# Based on http://intertwingly.net/blog/2004/07/31/URI-Equivalence
|
1277
|
+
it "should be equivalent to 'http://example.com/C%CC%A7'" do
|
1278
|
+
@uri.should == Addressable::URI.parse("http://example.com/C%CC%A7")
|
1279
|
+
end
|
1280
|
+
|
1281
|
+
it "should not change if encoded with the normalizing algorithm" do
|
1282
|
+
Addressable::URI.normalized_encode(@uri).to_s.should ==
|
1283
|
+
"http://example.com/%C3%87"
|
1284
|
+
Addressable::URI.normalized_encode(@uri, Addressable::URI).to_s.should ===
|
1285
|
+
"http://example.com/%C3%87"
|
1286
|
+
end
|
1287
|
+
|
1288
|
+
it "should raise an error if encoding with an unexpected return type" do
|
1289
|
+
(lambda do
|
1290
|
+
Addressable::URI.normalized_encode(@uri, Integer)
|
1291
|
+
end).should raise_error(TypeError)
|
1292
|
+
end
|
1293
|
+
|
1294
|
+
it "if percent encoded should be 'http://example.com/C%25CC%25A7'" do
|
1295
|
+
Addressable::URI.encode(@uri).to_s.should ==
|
1296
|
+
"http://example.com/%25C3%2587"
|
1297
|
+
end
|
1298
|
+
|
1299
|
+
it "if percent encoded should be 'http://example.com/C%25CC%25A7'" do
|
1300
|
+
Addressable::URI.encode(@uri, Addressable::URI).should ==
|
1301
|
+
Addressable::URI.parse("http://example.com/%25C3%2587")
|
1302
|
+
end
|
1303
|
+
|
1304
|
+
it "should raise an error if encoding with an unexpected return type" do
|
1305
|
+
(lambda do
|
1306
|
+
Addressable::URI.encode(@uri, Integer)
|
1307
|
+
end).should raise_error(TypeError)
|
1308
|
+
end
|
1309
|
+
|
1310
|
+
it "should be identical to its duplicate" do
|
1311
|
+
@uri.should == @uri.dup
|
1312
|
+
end
|
1313
|
+
end
|
1314
|
+
|
1315
|
+
describe Addressable::URI, "when parsed from " +
|
1316
|
+
"'http://example.com/?q=string'" do
|
1317
|
+
before do
|
1318
|
+
@uri = Addressable::URI.parse("http://example.com/?q=string")
|
1319
|
+
end
|
1320
|
+
|
1321
|
+
it "should use the 'http' scheme" do
|
1322
|
+
@uri.scheme.should == "http"
|
1323
|
+
end
|
1324
|
+
|
1325
|
+
it "should have an authority segment of 'example.com'" do
|
1326
|
+
@uri.authority.should == "example.com"
|
1327
|
+
end
|
1328
|
+
|
1329
|
+
it "should have a host of 'example.com'" do
|
1330
|
+
@uri.host.should == "example.com"
|
1331
|
+
end
|
1332
|
+
|
1333
|
+
it "should have no username" do
|
1334
|
+
@uri.user.should == nil
|
1335
|
+
end
|
1336
|
+
|
1337
|
+
it "should have no password" do
|
1338
|
+
@uri.password.should == nil
|
1339
|
+
end
|
1340
|
+
|
1341
|
+
it "should use port 80" do
|
1342
|
+
@uri.inferred_port.should == 80
|
1343
|
+
end
|
1344
|
+
|
1345
|
+
it "should have a path of '/'" do
|
1346
|
+
@uri.path.should == "/"
|
1347
|
+
end
|
1348
|
+
|
1349
|
+
it "should have a query string of 'q=string'" do
|
1350
|
+
@uri.query.should == "q=string"
|
1351
|
+
end
|
1352
|
+
|
1353
|
+
it "should have no fragment" do
|
1354
|
+
@uri.fragment.should == nil
|
1355
|
+
end
|
1356
|
+
|
1357
|
+
it "should be considered absolute" do
|
1358
|
+
@uri.should be_absolute
|
1359
|
+
end
|
1360
|
+
|
1361
|
+
it "should not be considered relative" do
|
1362
|
+
@uri.should_not be_relative
|
1363
|
+
end
|
1364
|
+
|
1365
|
+
it "should be considered to be in normal form" do
|
1366
|
+
@uri.normalize.should be_eql(@uri)
|
1367
|
+
end
|
1368
|
+
|
1369
|
+
it "should be identical to its duplicate" do
|
1370
|
+
@uri.should == @uri.dup
|
1371
|
+
end
|
1372
|
+
end
|
1373
|
+
|
1374
|
+
describe Addressable::URI, "when parsed from " +
|
1375
|
+
"'http://example.com:80/'" do
|
1376
|
+
before do
|
1377
|
+
@uri = Addressable::URI.parse("http://example.com:80/")
|
1378
|
+
end
|
1379
|
+
|
1380
|
+
it "should use the 'http' scheme" do
|
1381
|
+
@uri.scheme.should == "http"
|
1382
|
+
end
|
1383
|
+
|
1384
|
+
it "should have an authority segment of 'example.com:80'" do
|
1385
|
+
@uri.authority.should == "example.com:80"
|
1386
|
+
end
|
1387
|
+
|
1388
|
+
it "should have a host of 'example.com'" do
|
1389
|
+
@uri.host.should == "example.com"
|
1390
|
+
end
|
1391
|
+
|
1392
|
+
it "should have no username" do
|
1393
|
+
@uri.user.should == nil
|
1394
|
+
end
|
1395
|
+
|
1396
|
+
it "should have no password" do
|
1397
|
+
@uri.password.should == nil
|
1398
|
+
end
|
1399
|
+
|
1400
|
+
it "should use port 80" do
|
1401
|
+
@uri.port.should == 80
|
1402
|
+
end
|
1403
|
+
|
1404
|
+
it "should have a path of '/'" do
|
1405
|
+
@uri.path.should == "/"
|
1406
|
+
end
|
1407
|
+
|
1408
|
+
it "should have no query string" do
|
1409
|
+
@uri.query.should == nil
|
1410
|
+
end
|
1411
|
+
|
1412
|
+
it "should have no fragment" do
|
1413
|
+
@uri.fragment.should == nil
|
1414
|
+
end
|
1415
|
+
|
1416
|
+
it "should be considered absolute" do
|
1417
|
+
@uri.should be_absolute
|
1418
|
+
end
|
1419
|
+
|
1420
|
+
it "should not be considered relative" do
|
1421
|
+
@uri.should_not be_relative
|
1422
|
+
end
|
1423
|
+
|
1424
|
+
it "should be exactly equal to http://example.com:80/" do
|
1425
|
+
@uri.eql?(Addressable::URI.parse("http://example.com:80/")).should == true
|
1426
|
+
end
|
1427
|
+
|
1428
|
+
it "should be roughly equal to http://example.com/" do
|
1429
|
+
(@uri === Addressable::URI.parse("http://example.com/")).should == true
|
1430
|
+
end
|
1431
|
+
|
1432
|
+
it "should be roughly equal to the string 'http://example.com/'" do
|
1433
|
+
(@uri === "http://example.com/").should == true
|
1434
|
+
end
|
1435
|
+
|
1436
|
+
it "should not be roughly equal to the string " +
|
1437
|
+
"'http://example.com:bogus/'" do
|
1438
|
+
(lambda do
|
1439
|
+
(@uri === "http://example.com:bogus/").should == false
|
1440
|
+
end).should_not raise_error
|
1441
|
+
end
|
1442
|
+
|
1443
|
+
it "should result in itself when joined with itself" do
|
1444
|
+
@uri.join(@uri).to_s.should == "http://example.com:80/"
|
1445
|
+
@uri.join!(@uri).to_s.should == "http://example.com:80/"
|
1446
|
+
end
|
1447
|
+
|
1448
|
+
# Section 6.2.3 of RFC 3986
|
1449
|
+
it "should be equal to http://example.com/" do
|
1450
|
+
@uri.should == Addressable::URI.parse("http://example.com/")
|
1451
|
+
end
|
1452
|
+
|
1453
|
+
# Section 6.2.3 of RFC 3986
|
1454
|
+
it "should be equal to http://example.com:/" do
|
1455
|
+
@uri.should == Addressable::URI.parse("http://example.com:/")
|
1456
|
+
end
|
1457
|
+
|
1458
|
+
# Section 6.2.3 of RFC 3986
|
1459
|
+
it "should be equal to http://example.com:80/" do
|
1460
|
+
@uri.should == Addressable::URI.parse("http://example.com:80/")
|
1461
|
+
end
|
1462
|
+
|
1463
|
+
# Section 6.2.2.1 of RFC 3986
|
1464
|
+
it "should be equal to http://EXAMPLE.COM/" do
|
1465
|
+
@uri.should == Addressable::URI.parse("http://EXAMPLE.COM/")
|
1466
|
+
end
|
1467
|
+
|
1468
|
+
it "should correctly convert to a hash" do
|
1469
|
+
@uri.to_hash.should == {
|
1470
|
+
:scheme => "http",
|
1471
|
+
:user => nil,
|
1472
|
+
:password => nil,
|
1473
|
+
:host => "example.com",
|
1474
|
+
:port => 80,
|
1475
|
+
:path => "/",
|
1476
|
+
:query => nil,
|
1477
|
+
:fragment => nil
|
1478
|
+
}
|
1479
|
+
end
|
1480
|
+
|
1481
|
+
it "should be identical to its duplicate" do
|
1482
|
+
@uri.should == @uri.dup
|
1483
|
+
end
|
1484
|
+
end
|
1485
|
+
|
1486
|
+
describe Addressable::URI, "when parsed from " +
|
1487
|
+
"'http://example.com:8080/'" do
|
1488
|
+
before do
|
1489
|
+
@uri = Addressable::URI.parse("http://example.com:8080/")
|
1490
|
+
end
|
1491
|
+
|
1492
|
+
it "should use the 'http' scheme" do
|
1493
|
+
@uri.scheme.should == "http"
|
1494
|
+
end
|
1495
|
+
|
1496
|
+
it "should have an authority segment of 'example.com:8080'" do
|
1497
|
+
@uri.authority.should == "example.com:8080"
|
1498
|
+
end
|
1499
|
+
|
1500
|
+
it "should have a host of 'example.com'" do
|
1501
|
+
@uri.host.should == "example.com"
|
1502
|
+
end
|
1503
|
+
|
1504
|
+
it "should have no username" do
|
1505
|
+
@uri.user.should == nil
|
1506
|
+
end
|
1507
|
+
|
1508
|
+
it "should have no password" do
|
1509
|
+
@uri.password.should == nil
|
1510
|
+
end
|
1511
|
+
|
1512
|
+
it "should use port 8080" do
|
1513
|
+
@uri.port.should == 8080
|
1514
|
+
end
|
1515
|
+
|
1516
|
+
it "should have a path of '/'" do
|
1517
|
+
@uri.path.should == "/"
|
1518
|
+
end
|
1519
|
+
|
1520
|
+
it "should have no query string" do
|
1521
|
+
@uri.query.should == nil
|
1522
|
+
end
|
1523
|
+
|
1524
|
+
it "should have no fragment" do
|
1525
|
+
@uri.fragment.should == nil
|
1526
|
+
end
|
1527
|
+
|
1528
|
+
it "should be considered absolute" do
|
1529
|
+
@uri.should be_absolute
|
1530
|
+
end
|
1531
|
+
|
1532
|
+
it "should not be considered relative" do
|
1533
|
+
@uri.should_not be_relative
|
1534
|
+
end
|
1535
|
+
|
1536
|
+
it "should be exactly equal to http://example.com:8080/" do
|
1537
|
+
@uri.eql?(Addressable::URI.parse(
|
1538
|
+
"http://example.com:8080/")).should == true
|
1539
|
+
end
|
1540
|
+
|
1541
|
+
it "should have a route of 'http://example.com:8080/' from " +
|
1542
|
+
"'http://example.com/path/to/'" do
|
1543
|
+
@uri.route_from("http://example.com/path/to/").should ==
|
1544
|
+
Addressable::URI.parse("http://example.com:8080/")
|
1545
|
+
end
|
1546
|
+
|
1547
|
+
it "should have a route of 'http://example.com:8080/' from " +
|
1548
|
+
"'http://example.com:80/path/to/'" do
|
1549
|
+
@uri.route_from("http://example.com:80/path/to/").should ==
|
1550
|
+
Addressable::URI.parse("http://example.com:8080/")
|
1551
|
+
end
|
1552
|
+
|
1553
|
+
it "should have a route of '/' from " +
|
1554
|
+
"'http://example.com:8080/path/to/'" do
|
1555
|
+
@uri.route_from("http://example.com:8080/path/to/").should ==
|
1556
|
+
Addressable::URI.parse("/")
|
1557
|
+
end
|
1558
|
+
|
1559
|
+
it "should have a route of 'http://example.com:8080/' from " +
|
1560
|
+
"'http://user:pass@example.com/path/to/'" do
|
1561
|
+
@uri.route_from("http://user:pass@example.com/path/to/").should ==
|
1562
|
+
Addressable::URI.parse("http://example.com:8080/")
|
1563
|
+
end
|
1564
|
+
|
1565
|
+
it "should correctly convert to a hash" do
|
1566
|
+
@uri.to_hash.should == {
|
1567
|
+
:scheme => "http",
|
1568
|
+
:user => nil,
|
1569
|
+
:password => nil,
|
1570
|
+
:host => "example.com",
|
1571
|
+
:port => 8080,
|
1572
|
+
:path => "/",
|
1573
|
+
:query => nil,
|
1574
|
+
:fragment => nil
|
1575
|
+
}
|
1576
|
+
end
|
1577
|
+
|
1578
|
+
it "should be identical to its duplicate" do
|
1579
|
+
@uri.should == @uri.dup
|
1580
|
+
end
|
1581
|
+
end
|
1582
|
+
|
1583
|
+
describe Addressable::URI, "when parsed from " +
|
1584
|
+
"'http://example.com:%38%30/'" do
|
1585
|
+
before do
|
1586
|
+
@uri = Addressable::URI.parse("http://example.com:%38%30/")
|
1587
|
+
end
|
1588
|
+
|
1589
|
+
it "should have the correct port" do
|
1590
|
+
@uri.port.should == 80
|
1591
|
+
end
|
1592
|
+
|
1593
|
+
it "should not be considered to be in normal form" do
|
1594
|
+
@uri.normalize.should_not be_eql(@uri)
|
1595
|
+
end
|
1596
|
+
|
1597
|
+
it "should normalize to 'http://example.com/'" do
|
1598
|
+
@uri.normalize.should === "http://example.com/"
|
1599
|
+
end
|
1600
|
+
end
|
1601
|
+
|
1602
|
+
describe Addressable::URI, "when parsed from " +
|
1603
|
+
"'http://example.com/path/to/resource/'" do
|
1604
|
+
before do
|
1605
|
+
@uri = Addressable::URI.parse("http://example.com/path/to/resource/")
|
1606
|
+
end
|
1607
|
+
|
1608
|
+
it "should use the 'http' scheme" do
|
1609
|
+
@uri.scheme.should == "http"
|
1610
|
+
end
|
1611
|
+
|
1612
|
+
it "should have an authority segment of 'example.com'" do
|
1613
|
+
@uri.authority.should == "example.com"
|
1614
|
+
end
|
1615
|
+
|
1616
|
+
it "should have a host of 'example.com'" do
|
1617
|
+
@uri.host.should == "example.com"
|
1618
|
+
end
|
1619
|
+
|
1620
|
+
it "should have no username" do
|
1621
|
+
@uri.user.should == nil
|
1622
|
+
end
|
1623
|
+
|
1624
|
+
it "should have no password" do
|
1625
|
+
@uri.password.should == nil
|
1626
|
+
end
|
1627
|
+
|
1628
|
+
it "should use port 80" do
|
1629
|
+
@uri.inferred_port.should == 80
|
1630
|
+
end
|
1631
|
+
|
1632
|
+
it "should have a path of '/path/to/resource/'" do
|
1633
|
+
@uri.path.should == "/path/to/resource/"
|
1634
|
+
end
|
1635
|
+
|
1636
|
+
it "should have no query string" do
|
1637
|
+
@uri.query.should == nil
|
1638
|
+
end
|
1639
|
+
|
1640
|
+
it "should have no fragment" do
|
1641
|
+
@uri.fragment.should == nil
|
1642
|
+
end
|
1643
|
+
|
1644
|
+
it "should be considered absolute" do
|
1645
|
+
@uri.should be_absolute
|
1646
|
+
end
|
1647
|
+
|
1648
|
+
it "should not be considered relative" do
|
1649
|
+
@uri.should_not be_relative
|
1650
|
+
end
|
1651
|
+
|
1652
|
+
it "should be exactly equal to http://example.com:8080/" do
|
1653
|
+
@uri.eql?(Addressable::URI.parse(
|
1654
|
+
"http://example.com/path/to/resource/")).should == true
|
1655
|
+
end
|
1656
|
+
|
1657
|
+
it "should have a route of 'resource/' from " +
|
1658
|
+
"'http://example.com/path/to/'" do
|
1659
|
+
@uri.route_from("http://example.com/path/to/").should ==
|
1660
|
+
Addressable::URI.parse("resource/")
|
1661
|
+
end
|
1662
|
+
|
1663
|
+
it "should have a route of 'resource/' from " +
|
1664
|
+
"'http://example.com:80/path/to/'" do
|
1665
|
+
@uri.route_from("http://example.com:80/path/to/").should ==
|
1666
|
+
Addressable::URI.parse("resource/")
|
1667
|
+
end
|
1668
|
+
|
1669
|
+
it "should have a route of 'http://example.com/path/to/' from " +
|
1670
|
+
"'http://example.com:8080/path/to/'" do
|
1671
|
+
@uri.route_from("http://example.com:8080/path/to/").should ==
|
1672
|
+
Addressable::URI.parse("http://example.com/path/to/resource/")
|
1673
|
+
end
|
1674
|
+
|
1675
|
+
it "should have a route of 'http://example.com/path/to/' from " +
|
1676
|
+
"'http://user:pass@example.com/path/to/'" do
|
1677
|
+
@uri.route_from("http://user:pass@example.com/path/to/").should ==
|
1678
|
+
Addressable::URI.parse("http://example.com/path/to/resource/")
|
1679
|
+
end
|
1680
|
+
|
1681
|
+
it "should have a route of '/path/to/resource/' from " +
|
1682
|
+
"'http://example.com/to/resource/'" do
|
1683
|
+
@uri.route_from("http://example.com/to/resource/").should ==
|
1684
|
+
Addressable::URI.parse("/path/to/resource/")
|
1685
|
+
end
|
1686
|
+
|
1687
|
+
it "should correctly convert to a hash" do
|
1688
|
+
@uri.to_hash.should == {
|
1689
|
+
:scheme => "http",
|
1690
|
+
:user => nil,
|
1691
|
+
:password => nil,
|
1692
|
+
:host => "example.com",
|
1693
|
+
:port => nil,
|
1694
|
+
:path => "/path/to/resource/",
|
1695
|
+
:query => nil,
|
1696
|
+
:fragment => nil
|
1697
|
+
}
|
1698
|
+
end
|
1699
|
+
|
1700
|
+
it "should be identical to its duplicate" do
|
1701
|
+
@uri.should == @uri.dup
|
1702
|
+
end
|
1703
|
+
end
|
1704
|
+
|
1705
|
+
describe Addressable::URI, "when parsed from " +
|
1706
|
+
"'relative/path/to/resource'" do
|
1707
|
+
before do
|
1708
|
+
@uri = Addressable::URI.parse("relative/path/to/resource")
|
1709
|
+
end
|
1710
|
+
|
1711
|
+
it "should not have a scheme" do
|
1712
|
+
@uri.scheme.should == nil
|
1713
|
+
end
|
1714
|
+
|
1715
|
+
it "should not be considered ip-based" do
|
1716
|
+
@uri.should_not be_ip_based
|
1717
|
+
end
|
1718
|
+
|
1719
|
+
it "should not have an authority segment" do
|
1720
|
+
@uri.authority.should == nil
|
1721
|
+
end
|
1722
|
+
|
1723
|
+
it "should not have a host" do
|
1724
|
+
@uri.host.should == nil
|
1725
|
+
end
|
1726
|
+
|
1727
|
+
it "should have no username" do
|
1728
|
+
@uri.user.should == nil
|
1729
|
+
end
|
1730
|
+
|
1731
|
+
it "should have no password" do
|
1732
|
+
@uri.password.should == nil
|
1733
|
+
end
|
1734
|
+
|
1735
|
+
it "should not have a port" do
|
1736
|
+
@uri.port.should == nil
|
1737
|
+
end
|
1738
|
+
|
1739
|
+
it "should have a path of 'relative/path/to/resource'" do
|
1740
|
+
@uri.path.should == "relative/path/to/resource"
|
1741
|
+
end
|
1742
|
+
|
1743
|
+
it "should have no query string" do
|
1744
|
+
@uri.query.should == nil
|
1745
|
+
end
|
1746
|
+
|
1747
|
+
it "should have no fragment" do
|
1748
|
+
@uri.fragment.should == nil
|
1749
|
+
end
|
1750
|
+
|
1751
|
+
it "should not be considered absolute" do
|
1752
|
+
@uri.should_not be_absolute
|
1753
|
+
end
|
1754
|
+
|
1755
|
+
it "should be considered relative" do
|
1756
|
+
@uri.should be_relative
|
1757
|
+
end
|
1758
|
+
|
1759
|
+
it "should raise an error if routing is attempted" do
|
1760
|
+
(lambda do
|
1761
|
+
@uri.route_to("http://example.com/")
|
1762
|
+
end).should raise_error(ArgumentError, /relative\/path\/to\/resource/)
|
1763
|
+
(lambda do
|
1764
|
+
@uri.route_from("http://example.com/")
|
1765
|
+
end).should raise_error(ArgumentError, /relative\/path\/to\/resource/)
|
1766
|
+
end
|
1767
|
+
|
1768
|
+
it "when joined with 'another/relative/path' should be " +
|
1769
|
+
"'relative/path/to/another/relative/path'" do
|
1770
|
+
@uri.join('another/relative/path').should ==
|
1771
|
+
Addressable::URI.parse("relative/path/to/another/relative/path")
|
1772
|
+
end
|
1773
|
+
|
1774
|
+
it "should be identical to its duplicate" do
|
1775
|
+
@uri.should == @uri.dup
|
1776
|
+
end
|
1777
|
+
end
|
1778
|
+
|
1779
|
+
describe Addressable::URI, "when parsed from " +
|
1780
|
+
"'relative_path_with_no_slashes'" do
|
1781
|
+
before do
|
1782
|
+
@uri = Addressable::URI.parse("relative_path_with_no_slashes")
|
1783
|
+
end
|
1784
|
+
|
1785
|
+
it "should not have a scheme" do
|
1786
|
+
@uri.scheme.should == nil
|
1787
|
+
end
|
1788
|
+
|
1789
|
+
it "should not be considered ip-based" do
|
1790
|
+
@uri.should_not be_ip_based
|
1791
|
+
end
|
1792
|
+
|
1793
|
+
it "should not have an authority segment" do
|
1794
|
+
@uri.authority.should == nil
|
1795
|
+
end
|
1796
|
+
|
1797
|
+
it "should not have a host" do
|
1798
|
+
@uri.host.should == nil
|
1799
|
+
end
|
1800
|
+
|
1801
|
+
it "should have no username" do
|
1802
|
+
@uri.user.should == nil
|
1803
|
+
end
|
1804
|
+
|
1805
|
+
it "should have no password" do
|
1806
|
+
@uri.password.should == nil
|
1807
|
+
end
|
1808
|
+
|
1809
|
+
it "should not have a port" do
|
1810
|
+
@uri.port.should == nil
|
1811
|
+
end
|
1812
|
+
|
1813
|
+
it "should have a path of 'relative_path_with_no_slashes'" do
|
1814
|
+
@uri.path.should == "relative_path_with_no_slashes"
|
1815
|
+
end
|
1816
|
+
|
1817
|
+
it "should have no query string" do
|
1818
|
+
@uri.query.should == nil
|
1819
|
+
end
|
1820
|
+
|
1821
|
+
it "should have no fragment" do
|
1822
|
+
@uri.fragment.should == nil
|
1823
|
+
end
|
1824
|
+
|
1825
|
+
it "should not be considered absolute" do
|
1826
|
+
@uri.should_not be_absolute
|
1827
|
+
end
|
1828
|
+
|
1829
|
+
it "should be considered relative" do
|
1830
|
+
@uri.should be_relative
|
1831
|
+
end
|
1832
|
+
|
1833
|
+
it "when joined with 'another_relative_path' should be " +
|
1834
|
+
"'another_relative_path'" do
|
1835
|
+
@uri.join('another_relative_path').should ==
|
1836
|
+
Addressable::URI.parse("another_relative_path")
|
1837
|
+
end
|
1838
|
+
end
|
1839
|
+
|
1840
|
+
describe Addressable::URI, "when parsed from " +
|
1841
|
+
"'http://example.com/file.txt'" do
|
1842
|
+
before do
|
1843
|
+
@uri = Addressable::URI.parse("http://example.com/file.txt")
|
1844
|
+
end
|
1845
|
+
|
1846
|
+
it "should have a scheme of 'http'" do
|
1847
|
+
@uri.scheme.should == "http"
|
1848
|
+
end
|
1849
|
+
|
1850
|
+
it "should have an authority segment of 'example.com'" do
|
1851
|
+
@uri.authority.should == "example.com"
|
1852
|
+
end
|
1853
|
+
|
1854
|
+
it "should have a host of 'example.com'" do
|
1855
|
+
@uri.host.should == "example.com"
|
1856
|
+
end
|
1857
|
+
|
1858
|
+
it "should have no username" do
|
1859
|
+
@uri.user.should == nil
|
1860
|
+
end
|
1861
|
+
|
1862
|
+
it "should have no password" do
|
1863
|
+
@uri.password.should == nil
|
1864
|
+
end
|
1865
|
+
|
1866
|
+
it "should use port 80" do
|
1867
|
+
@uri.inferred_port.should == 80
|
1868
|
+
end
|
1869
|
+
|
1870
|
+
it "should have a path of '/file.txt'" do
|
1871
|
+
@uri.path.should == "/file.txt"
|
1872
|
+
end
|
1873
|
+
|
1874
|
+
it "should have a basename of 'file.txt'" do
|
1875
|
+
@uri.basename.should == "file.txt"
|
1876
|
+
end
|
1877
|
+
|
1878
|
+
it "should have an extname of '.txt'" do
|
1879
|
+
@uri.extname.should == ".txt"
|
1880
|
+
end
|
1881
|
+
|
1882
|
+
it "should have no query string" do
|
1883
|
+
@uri.query.should == nil
|
1884
|
+
end
|
1885
|
+
|
1886
|
+
it "should have no fragment" do
|
1887
|
+
@uri.fragment.should == nil
|
1888
|
+
end
|
1889
|
+
end
|
1890
|
+
|
1891
|
+
describe Addressable::URI, "when parsed from " +
|
1892
|
+
"'http://example.com/file.txt;parameter'" do
|
1893
|
+
before do
|
1894
|
+
@uri = Addressable::URI.parse("http://example.com/file.txt;parameter")
|
1895
|
+
end
|
1896
|
+
|
1897
|
+
it "should have a scheme of 'http'" do
|
1898
|
+
@uri.scheme.should == "http"
|
1899
|
+
end
|
1900
|
+
|
1901
|
+
it "should have an authority segment of 'example.com'" do
|
1902
|
+
@uri.authority.should == "example.com"
|
1903
|
+
end
|
1904
|
+
|
1905
|
+
it "should have a host of 'example.com'" do
|
1906
|
+
@uri.host.should == "example.com"
|
1907
|
+
end
|
1908
|
+
|
1909
|
+
it "should have no username" do
|
1910
|
+
@uri.user.should == nil
|
1911
|
+
end
|
1912
|
+
|
1913
|
+
it "should have no password" do
|
1914
|
+
@uri.password.should == nil
|
1915
|
+
end
|
1916
|
+
|
1917
|
+
it "should use port 80" do
|
1918
|
+
@uri.inferred_port.should == 80
|
1919
|
+
end
|
1920
|
+
|
1921
|
+
it "should have a path of '/file.txt;parameter'" do
|
1922
|
+
@uri.path.should == "/file.txt;parameter"
|
1923
|
+
end
|
1924
|
+
|
1925
|
+
it "should have a basename of 'file.txt'" do
|
1926
|
+
@uri.basename.should == "file.txt"
|
1927
|
+
end
|
1928
|
+
|
1929
|
+
it "should have an extname of '.txt'" do
|
1930
|
+
@uri.extname.should == ".txt"
|
1931
|
+
end
|
1932
|
+
|
1933
|
+
it "should have no query string" do
|
1934
|
+
@uri.query.should == nil
|
1935
|
+
end
|
1936
|
+
|
1937
|
+
it "should have no fragment" do
|
1938
|
+
@uri.fragment.should == nil
|
1939
|
+
end
|
1940
|
+
end
|
1941
|
+
|
1942
|
+
describe Addressable::URI, "when parsed from " +
|
1943
|
+
"'http://example.com/file.txt;x=y'" do
|
1944
|
+
before do
|
1945
|
+
@uri = Addressable::URI.parse("http://example.com/file.txt;x=y")
|
1946
|
+
end
|
1947
|
+
|
1948
|
+
it "should have a scheme of 'http'" do
|
1949
|
+
@uri.scheme.should == "http"
|
1950
|
+
end
|
1951
|
+
|
1952
|
+
it "should have a scheme of 'http'" do
|
1953
|
+
@uri.scheme.should == "http"
|
1954
|
+
end
|
1955
|
+
|
1956
|
+
it "should have an authority segment of 'example.com'" do
|
1957
|
+
@uri.authority.should == "example.com"
|
1958
|
+
end
|
1959
|
+
|
1960
|
+
it "should have a host of 'example.com'" do
|
1961
|
+
@uri.host.should == "example.com"
|
1962
|
+
end
|
1963
|
+
|
1964
|
+
it "should have no username" do
|
1965
|
+
@uri.user.should == nil
|
1966
|
+
end
|
1967
|
+
|
1968
|
+
it "should have no password" do
|
1969
|
+
@uri.password.should == nil
|
1970
|
+
end
|
1971
|
+
|
1972
|
+
it "should use port 80" do
|
1973
|
+
@uri.inferred_port.should == 80
|
1974
|
+
end
|
1975
|
+
|
1976
|
+
it "should have a path of '/file.txt;x=y'" do
|
1977
|
+
@uri.path.should == "/file.txt;x=y"
|
1978
|
+
end
|
1979
|
+
|
1980
|
+
it "should have an extname of '.txt'" do
|
1981
|
+
@uri.extname.should == ".txt"
|
1982
|
+
end
|
1983
|
+
|
1984
|
+
it "should have no query string" do
|
1985
|
+
@uri.query.should == nil
|
1986
|
+
end
|
1987
|
+
|
1988
|
+
it "should have no fragment" do
|
1989
|
+
@uri.fragment.should == nil
|
1990
|
+
end
|
1991
|
+
|
1992
|
+
it "should be considered to be in normal form" do
|
1993
|
+
@uri.normalize.should be_eql(@uri)
|
1994
|
+
end
|
1995
|
+
end
|
1996
|
+
|
1997
|
+
describe Addressable::URI, "when parsed from " +
|
1998
|
+
"'svn+ssh://developername@rubyforge.org/var/svn/project'" do
|
1999
|
+
before do
|
2000
|
+
@uri = Addressable::URI.parse(
|
2001
|
+
"svn+ssh://developername@rubyforge.org/var/svn/project"
|
2002
|
+
)
|
2003
|
+
end
|
2004
|
+
|
2005
|
+
it "should have a scheme of 'svn+ssh'" do
|
2006
|
+
@uri.scheme.should == "svn+ssh"
|
2007
|
+
end
|
2008
|
+
|
2009
|
+
it "should be considered to be ip-based" do
|
2010
|
+
@uri.should be_ip_based
|
2011
|
+
end
|
2012
|
+
|
2013
|
+
it "should have a path of '/var/svn/project'" do
|
2014
|
+
@uri.path.should == "/var/svn/project"
|
2015
|
+
end
|
2016
|
+
|
2017
|
+
it "should have a username of 'developername'" do
|
2018
|
+
@uri.user.should == "developername"
|
2019
|
+
end
|
2020
|
+
|
2021
|
+
it "should have no password" do
|
2022
|
+
@uri.password.should == nil
|
2023
|
+
end
|
2024
|
+
|
2025
|
+
it "should be considered to be in normal form" do
|
2026
|
+
@uri.normalize.should be_eql(@uri)
|
2027
|
+
end
|
2028
|
+
end
|
2029
|
+
|
2030
|
+
describe Addressable::URI, "when parsed from " +
|
2031
|
+
"'ssh+svn://developername@RUBYFORGE.ORG/var/svn/project'" do
|
2032
|
+
before do
|
2033
|
+
@uri = Addressable::URI.parse(
|
2034
|
+
"ssh+svn://developername@RUBYFORGE.ORG/var/svn/project"
|
2035
|
+
)
|
2036
|
+
end
|
2037
|
+
|
2038
|
+
it "should have a scheme of 'ssh+svn'" do
|
2039
|
+
@uri.scheme.should == "ssh+svn"
|
2040
|
+
end
|
2041
|
+
|
2042
|
+
it "should have a normalized scheme of 'svn+ssh'" do
|
2043
|
+
@uri.normalized_scheme.should == "svn+ssh"
|
2044
|
+
end
|
2045
|
+
|
2046
|
+
it "should have a normalized site of 'svn+ssh'" do
|
2047
|
+
@uri.normalized_site.should == "svn+ssh://developername@rubyforge.org"
|
2048
|
+
end
|
2049
|
+
|
2050
|
+
it "should not be considered to be ip-based" do
|
2051
|
+
@uri.should_not be_ip_based
|
2052
|
+
end
|
2053
|
+
|
2054
|
+
it "should have a path of '/var/svn/project'" do
|
2055
|
+
@uri.path.should == "/var/svn/project"
|
2056
|
+
end
|
2057
|
+
|
2058
|
+
it "should have a username of 'developername'" do
|
2059
|
+
@uri.user.should == "developername"
|
2060
|
+
end
|
2061
|
+
|
2062
|
+
it "should have no password" do
|
2063
|
+
@uri.password.should == nil
|
2064
|
+
end
|
2065
|
+
|
2066
|
+
it "should not be considered to be in normal form" do
|
2067
|
+
@uri.normalize.should_not be_eql(@uri)
|
2068
|
+
end
|
2069
|
+
end
|
2070
|
+
|
2071
|
+
describe Addressable::URI, "when parsed from " +
|
2072
|
+
"'mailto:user@example.com'" do
|
2073
|
+
before do
|
2074
|
+
@uri = Addressable::URI.parse("mailto:user@example.com")
|
2075
|
+
end
|
2076
|
+
|
2077
|
+
it "should have a scheme of 'mailto'" do
|
2078
|
+
@uri.scheme.should == "mailto"
|
2079
|
+
end
|
2080
|
+
|
2081
|
+
it "should not be considered to be ip-based" do
|
2082
|
+
@uri.should_not be_ip_based
|
2083
|
+
end
|
2084
|
+
|
2085
|
+
it "should have a path of 'user@example.com'" do
|
2086
|
+
@uri.path.should == "user@example.com"
|
2087
|
+
end
|
2088
|
+
|
2089
|
+
it "should have no user" do
|
2090
|
+
@uri.user.should == nil
|
2091
|
+
end
|
2092
|
+
|
2093
|
+
it "should be considered to be in normal form" do
|
2094
|
+
@uri.normalize.should be_eql(@uri)
|
2095
|
+
end
|
2096
|
+
end
|
2097
|
+
|
2098
|
+
describe Addressable::URI, "when parsed from " +
|
2099
|
+
"'tag:example.com,2006-08-18:/path/to/something'" do
|
2100
|
+
before do
|
2101
|
+
@uri = Addressable::URI.parse(
|
2102
|
+
"tag:example.com,2006-08-18:/path/to/something")
|
2103
|
+
end
|
2104
|
+
|
2105
|
+
it "should have a scheme of 'tag'" do
|
2106
|
+
@uri.scheme.should == "tag"
|
2107
|
+
end
|
2108
|
+
|
2109
|
+
it "should be considered to be ip-based" do
|
2110
|
+
@uri.should_not be_ip_based
|
2111
|
+
end
|
2112
|
+
|
2113
|
+
it "should have a path of " +
|
2114
|
+
"'example.com,2006-08-18:/path/to/something'" do
|
2115
|
+
@uri.path.should == "example.com,2006-08-18:/path/to/something"
|
2116
|
+
end
|
2117
|
+
|
2118
|
+
it "should have no user" do
|
2119
|
+
@uri.user.should == nil
|
2120
|
+
end
|
2121
|
+
|
2122
|
+
it "should be considered to be in normal form" do
|
2123
|
+
@uri.normalize.should be_eql(@uri)
|
2124
|
+
end
|
2125
|
+
end
|
2126
|
+
|
2127
|
+
describe Addressable::URI, "when parsed from " +
|
2128
|
+
"'http://example.com/x;y/'" do
|
2129
|
+
before do
|
2130
|
+
@uri = Addressable::URI.parse("http://example.com/x;y/")
|
2131
|
+
end
|
2132
|
+
|
2133
|
+
it "should be considered to be in normal form" do
|
2134
|
+
@uri.normalize.should be_eql(@uri)
|
2135
|
+
end
|
2136
|
+
end
|
2137
|
+
|
2138
|
+
describe Addressable::URI, "when parsed from " +
|
2139
|
+
"'http://example.com/?x=1&y=2'" do
|
2140
|
+
before do
|
2141
|
+
@uri = Addressable::URI.parse("http://example.com/?x=1&y=2")
|
2142
|
+
end
|
2143
|
+
|
2144
|
+
it "should be considered to be in normal form" do
|
2145
|
+
@uri.normalize.should be_eql(@uri)
|
2146
|
+
end
|
2147
|
+
end
|
2148
|
+
|
2149
|
+
describe Addressable::URI, "when parsed from " +
|
2150
|
+
"'view-source:http://example.com/'" do
|
2151
|
+
before do
|
2152
|
+
@uri = Addressable::URI.parse("view-source:http://example.com/")
|
2153
|
+
end
|
2154
|
+
|
2155
|
+
it "should have a scheme of 'view-source'" do
|
2156
|
+
@uri.scheme.should == "view-source"
|
2157
|
+
end
|
2158
|
+
|
2159
|
+
it "should have a path of 'http://example.com/'" do
|
2160
|
+
@uri.path.should == "http://example.com/"
|
2161
|
+
end
|
2162
|
+
|
2163
|
+
it "should be considered to be in normal form" do
|
2164
|
+
@uri.normalize.should be_eql(@uri)
|
2165
|
+
end
|
2166
|
+
end
|
2167
|
+
|
2168
|
+
describe Addressable::URI, "when parsed from " +
|
2169
|
+
"'http://user:pass@example.com/path/to/resource?query=x#fragment'" do
|
2170
|
+
before do
|
2171
|
+
@uri = Addressable::URI.parse(
|
2172
|
+
"http://user:pass@example.com/path/to/resource?query=x#fragment")
|
2173
|
+
end
|
2174
|
+
|
2175
|
+
it "should use the 'http' scheme" do
|
2176
|
+
@uri.scheme.should == "http"
|
2177
|
+
end
|
2178
|
+
|
2179
|
+
it "should have an authority segment of 'user:pass@example.com'" do
|
2180
|
+
@uri.authority.should == "user:pass@example.com"
|
2181
|
+
end
|
2182
|
+
|
2183
|
+
it "should have a username of 'user'" do
|
2184
|
+
@uri.user.should == "user"
|
2185
|
+
end
|
2186
|
+
|
2187
|
+
it "should have a password of 'pass'" do
|
2188
|
+
@uri.password.should == "pass"
|
2189
|
+
end
|
2190
|
+
|
2191
|
+
it "should have a host of 'example.com'" do
|
2192
|
+
@uri.host.should == "example.com"
|
2193
|
+
end
|
2194
|
+
|
2195
|
+
it "should use port 80" do
|
2196
|
+
@uri.inferred_port.should == 80
|
2197
|
+
end
|
2198
|
+
|
2199
|
+
it "should have a path of '/path/to/resource'" do
|
2200
|
+
@uri.path.should == "/path/to/resource"
|
2201
|
+
end
|
2202
|
+
|
2203
|
+
it "should have a query string of 'query=x'" do
|
2204
|
+
@uri.query.should == "query=x"
|
2205
|
+
end
|
2206
|
+
|
2207
|
+
it "should have a fragment of 'fragment'" do
|
2208
|
+
@uri.fragment.should == "fragment"
|
2209
|
+
end
|
2210
|
+
|
2211
|
+
it "should be considered to be in normal form" do
|
2212
|
+
@uri.normalize.should be_eql(@uri)
|
2213
|
+
end
|
2214
|
+
|
2215
|
+
it "should have a route of '/path/' to " +
|
2216
|
+
"'http://user:pass@example.com/path/'" do
|
2217
|
+
@uri.route_to("http://user:pass@example.com/path/").should ==
|
2218
|
+
Addressable::URI.parse("/path/")
|
2219
|
+
end
|
2220
|
+
|
2221
|
+
it "should have a route of '/path/to/resource?query=x#fragment' " +
|
2222
|
+
"from 'http://user:pass@example.com/path/'" do
|
2223
|
+
@uri.route_from("http://user:pass@example.com/path/").should ==
|
2224
|
+
Addressable::URI.parse("to/resource?query=x#fragment")
|
2225
|
+
end
|
2226
|
+
|
2227
|
+
it "should have a route of '?query=x#fragment' " +
|
2228
|
+
"from 'http://user:pass@example.com/path/to/resource'" do
|
2229
|
+
@uri.route_from("http://user:pass@example.com/path/to/resource").should ==
|
2230
|
+
Addressable::URI.parse("?query=x#fragment")
|
2231
|
+
end
|
2232
|
+
|
2233
|
+
it "should have a route of '#fragment' " +
|
2234
|
+
"from 'http://user:pass@example.com/path/to/resource?query=x'" do
|
2235
|
+
@uri.route_from(
|
2236
|
+
"http://user:pass@example.com/path/to/resource?query=x").should ==
|
2237
|
+
Addressable::URI.parse("#fragment")
|
2238
|
+
end
|
2239
|
+
|
2240
|
+
it "should have a route of '#fragment' from " +
|
2241
|
+
"'http://user:pass@example.com/path/to/resource?query=x#fragment'" do
|
2242
|
+
@uri.route_from(
|
2243
|
+
"http://user:pass@example.com/path/to/resource?query=x#fragment"
|
2244
|
+
).should == Addressable::URI.parse("#fragment")
|
2245
|
+
end
|
2246
|
+
|
2247
|
+
it "should have a route of 'http://elsewhere.com/' to " +
|
2248
|
+
"'http://elsewhere.com/'" do
|
2249
|
+
@uri.route_to("http://elsewhere.com/").should ==
|
2250
|
+
Addressable::URI.parse("http://elsewhere.com/")
|
2251
|
+
end
|
2252
|
+
|
2253
|
+
it "should have a route of " +
|
2254
|
+
"'http://user:pass@example.com/path/to/resource?query=x#fragment' " +
|
2255
|
+
"from 'http://example.com/path/to/'" do
|
2256
|
+
@uri.route_from("http://elsewhere.com/path/to/").should ==
|
2257
|
+
Addressable::URI.parse(
|
2258
|
+
"http://user:pass@example.com/path/to/resource?query=x#fragment")
|
2259
|
+
end
|
2260
|
+
|
2261
|
+
it "should have the correct scheme after assignment" do
|
2262
|
+
@uri.scheme = "ftp"
|
2263
|
+
@uri.scheme.should == "ftp"
|
2264
|
+
@uri.to_s.should ==
|
2265
|
+
"ftp://user:pass@example.com/path/to/resource?query=x#fragment"
|
2266
|
+
@uri.to_str.should ==
|
2267
|
+
"ftp://user:pass@example.com/path/to/resource?query=x#fragment"
|
2268
|
+
@uri.scheme = "bogus!"
|
2269
|
+
@uri.scheme.should == "bogus!"
|
2270
|
+
@uri.normalized_scheme.should == "bogus%21"
|
2271
|
+
@uri.normalize.to_s.should ==
|
2272
|
+
"bogus%21://user:pass@example.com/path/to/resource?query=x#fragment"
|
2273
|
+
@uri.normalize.to_str.should ==
|
2274
|
+
"bogus%21://user:pass@example.com/path/to/resource?query=x#fragment"
|
2275
|
+
end
|
2276
|
+
|
2277
|
+
it "should have the correct site segment after assignment" do
|
2278
|
+
@uri.site = "https://newuser:newpass@example.com:443"
|
2279
|
+
@uri.scheme.should == "https"
|
2280
|
+
@uri.authority.should == "newuser:newpass@example.com:443"
|
2281
|
+
@uri.user.should == "newuser"
|
2282
|
+
@uri.password.should == "newpass"
|
2283
|
+
@uri.userinfo.should == "newuser:newpass"
|
2284
|
+
@uri.normalized_userinfo.should == "newuser:newpass"
|
2285
|
+
@uri.host.should == "example.com"
|
2286
|
+
@uri.port.should == 443
|
2287
|
+
@uri.inferred_port.should == 443
|
2288
|
+
@uri.to_s.should ==
|
2289
|
+
"https://newuser:newpass@example.com:443" +
|
2290
|
+
"/path/to/resource?query=x#fragment"
|
2291
|
+
end
|
2292
|
+
|
2293
|
+
it "should have the correct authority segment after assignment" do
|
2294
|
+
@uri.authority = "newuser:newpass@example.com:80"
|
2295
|
+
@uri.authority.should == "newuser:newpass@example.com:80"
|
2296
|
+
@uri.user.should == "newuser"
|
2297
|
+
@uri.password.should == "newpass"
|
2298
|
+
@uri.userinfo.should == "newuser:newpass"
|
2299
|
+
@uri.normalized_userinfo.should == "newuser:newpass"
|
2300
|
+
@uri.host.should == "example.com"
|
2301
|
+
@uri.port.should == 80
|
2302
|
+
@uri.inferred_port.should == 80
|
2303
|
+
@uri.to_s.should ==
|
2304
|
+
"http://newuser:newpass@example.com:80" +
|
2305
|
+
"/path/to/resource?query=x#fragment"
|
2306
|
+
end
|
2307
|
+
|
2308
|
+
it "should have the correct userinfo segment after assignment" do
|
2309
|
+
@uri.userinfo = "newuser:newpass"
|
2310
|
+
@uri.userinfo.should == "newuser:newpass"
|
2311
|
+
@uri.authority.should == "newuser:newpass@example.com"
|
2312
|
+
@uri.user.should == "newuser"
|
2313
|
+
@uri.password.should == "newpass"
|
2314
|
+
@uri.host.should == "example.com"
|
2315
|
+
@uri.port.should == nil
|
2316
|
+
@uri.inferred_port.should == 80
|
2317
|
+
@uri.to_s.should ==
|
2318
|
+
"http://newuser:newpass@example.com" +
|
2319
|
+
"/path/to/resource?query=x#fragment"
|
2320
|
+
end
|
2321
|
+
|
2322
|
+
it "should have the correct username after assignment" do
|
2323
|
+
@uri.user = "newuser"
|
2324
|
+
@uri.user.should == "newuser"
|
2325
|
+
@uri.authority.should == "newuser:pass@example.com"
|
2326
|
+
end
|
2327
|
+
|
2328
|
+
it "should have the correct password after assignment" do
|
2329
|
+
@uri.password = "newpass"
|
2330
|
+
@uri.password.should == "newpass"
|
2331
|
+
@uri.authority.should == "user:newpass@example.com"
|
2332
|
+
end
|
2333
|
+
|
2334
|
+
it "should have the correct host after assignment" do
|
2335
|
+
@uri.host = "newexample.com"
|
2336
|
+
@uri.host.should == "newexample.com"
|
2337
|
+
@uri.authority.should == "user:pass@newexample.com"
|
2338
|
+
end
|
2339
|
+
|
2340
|
+
it "should have the correct port after assignment" do
|
2341
|
+
@uri.port = 8080
|
2342
|
+
@uri.port.should == 8080
|
2343
|
+
@uri.authority.should == "user:pass@example.com:8080"
|
2344
|
+
end
|
2345
|
+
|
2346
|
+
it "should have the correct path after assignment" do
|
2347
|
+
@uri.path = "/newpath/to/resource"
|
2348
|
+
@uri.path.should == "/newpath/to/resource"
|
2349
|
+
@uri.to_s.should ==
|
2350
|
+
"http://user:pass@example.com/newpath/to/resource?query=x#fragment"
|
2351
|
+
end
|
2352
|
+
|
2353
|
+
it "should have the correct scheme and authority after nil assignment" do
|
2354
|
+
@uri.site = nil
|
2355
|
+
@uri.scheme.should == nil
|
2356
|
+
@uri.authority.should == nil
|
2357
|
+
@uri.to_s.should == "/path/to/resource?query=x#fragment"
|
2358
|
+
end
|
2359
|
+
|
2360
|
+
it "should have the correct scheme and authority after assignment" do
|
2361
|
+
@uri.site = "file://"
|
2362
|
+
@uri.scheme.should == "file"
|
2363
|
+
@uri.authority.should == ""
|
2364
|
+
@uri.to_s.should == "file:///path/to/resource?query=x#fragment"
|
2365
|
+
end
|
2366
|
+
|
2367
|
+
it "should have the correct path after nil assignment" do
|
2368
|
+
@uri.path = nil
|
2369
|
+
@uri.path.should == ""
|
2370
|
+
@uri.to_s.should ==
|
2371
|
+
"http://user:pass@example.com?query=x#fragment"
|
2372
|
+
end
|
2373
|
+
|
2374
|
+
it "should have the correct query string after assignment" do
|
2375
|
+
@uri.query = "newquery=x"
|
2376
|
+
@uri.query.should == "newquery=x"
|
2377
|
+
@uri.to_s.should ==
|
2378
|
+
"http://user:pass@example.com/path/to/resource?newquery=x#fragment"
|
2379
|
+
@uri.query = nil
|
2380
|
+
@uri.query.should == nil
|
2381
|
+
@uri.to_s.should ==
|
2382
|
+
"http://user:pass@example.com/path/to/resource#fragment"
|
2383
|
+
end
|
2384
|
+
|
2385
|
+
it "should have the correct query string after hash assignment" do
|
2386
|
+
@uri.query_values = {"?uestion mark"=>"=sign", "hello"=>"g\xC3\xBCnther"}
|
2387
|
+
@uri.query.split("&").should include("%3Fuestion%20mark=%3Dsign")
|
2388
|
+
@uri.query.split("&").should include("hello=g%C3%BCnther")
|
2389
|
+
@uri.query_values.should == {
|
2390
|
+
"?uestion mark"=>"=sign", "hello"=>"g\xC3\xBCnther"
|
2391
|
+
}
|
2392
|
+
end
|
2393
|
+
|
2394
|
+
it "should have the correct query string after flag hash assignment" do
|
2395
|
+
@uri.query_values = {'flag?1' => true, 'fl=ag2' => true, 'flag3' => true}
|
2396
|
+
@uri.query.split("&").should include("flag%3F1")
|
2397
|
+
@uri.query.split("&").should include("fl%3Dag2")
|
2398
|
+
@uri.query.split("&").should include("flag3")
|
2399
|
+
@uri.query_values.should == {
|
2400
|
+
'flag?1' => true, 'fl=ag2' => true, 'flag3' => true
|
2401
|
+
}
|
2402
|
+
end
|
2403
|
+
|
2404
|
+
it "should raise an error if query values are set to a bogus type" do
|
2405
|
+
(lambda do
|
2406
|
+
@uri.query_values = "bogus"
|
2407
|
+
end).should raise_error(TypeError)
|
2408
|
+
end
|
2409
|
+
|
2410
|
+
it "should have the correct fragment after assignment" do
|
2411
|
+
@uri.fragment = "newfragment"
|
2412
|
+
@uri.fragment.should == "newfragment"
|
2413
|
+
@uri.to_s.should ==
|
2414
|
+
"http://user:pass@example.com/path/to/resource?query=x#newfragment"
|
2415
|
+
|
2416
|
+
@uri.fragment = nil
|
2417
|
+
@uri.fragment.should == nil
|
2418
|
+
@uri.to_s.should ==
|
2419
|
+
"http://user:pass@example.com/path/to/resource?query=x"
|
2420
|
+
end
|
2421
|
+
|
2422
|
+
it "should have the correct values after a merge" do
|
2423
|
+
@uri.merge(:fragment => "newfragment").to_s.should ==
|
2424
|
+
"http://user:pass@example.com/path/to/resource?query=x#newfragment"
|
2425
|
+
end
|
2426
|
+
|
2427
|
+
it "should have the correct values after a merge" do
|
2428
|
+
@uri.merge(:fragment => nil).to_s.should ==
|
2429
|
+
"http://user:pass@example.com/path/to/resource?query=x"
|
2430
|
+
end
|
2431
|
+
|
2432
|
+
it "should have the correct values after a merge" do
|
2433
|
+
@uri.merge(:userinfo => "newuser:newpass").to_s.should ==
|
2434
|
+
"http://newuser:newpass@example.com/path/to/resource?query=x#fragment"
|
2435
|
+
end
|
2436
|
+
|
2437
|
+
it "should have the correct values after a merge" do
|
2438
|
+
@uri.merge(:userinfo => nil).to_s.should ==
|
2439
|
+
"http://example.com/path/to/resource?query=x#fragment"
|
2440
|
+
end
|
2441
|
+
|
2442
|
+
it "should have the correct values after a merge" do
|
2443
|
+
@uri.merge(:path => "newpath").to_s.should ==
|
2444
|
+
"http://user:pass@example.com/newpath?query=x#fragment"
|
2445
|
+
end
|
2446
|
+
|
2447
|
+
it "should have the correct values after a merge" do
|
2448
|
+
@uri.merge(:port => "42", :path => "newpath", :query => "").to_s.should ==
|
2449
|
+
"http://user:pass@example.com:42/newpath?#fragment"
|
2450
|
+
end
|
2451
|
+
|
2452
|
+
it "should have the correct values after a merge" do
|
2453
|
+
@uri.merge(:authority => "foo:bar@baz:42").to_s.should ==
|
2454
|
+
"http://foo:bar@baz:42/path/to/resource?query=x#fragment"
|
2455
|
+
# Ensure the operation was not destructive
|
2456
|
+
@uri.to_s.should ==
|
2457
|
+
"http://user:pass@example.com/path/to/resource?query=x#fragment"
|
2458
|
+
end
|
2459
|
+
|
2460
|
+
it "should have the correct values after a destructive merge" do
|
2461
|
+
@uri.merge!(:authority => "foo:bar@baz:42")
|
2462
|
+
# Ensure the operation was destructive
|
2463
|
+
@uri.to_s.should ==
|
2464
|
+
"http://foo:bar@baz:42/path/to/resource?query=x#fragment"
|
2465
|
+
end
|
2466
|
+
|
2467
|
+
it "should fail to merge with bogus values" do
|
2468
|
+
(lambda do
|
2469
|
+
@uri.merge(:port => "bogus")
|
2470
|
+
end).should raise_error(Addressable::URI::InvalidURIError)
|
2471
|
+
end
|
2472
|
+
|
2473
|
+
it "should fail to merge with bogus values" do
|
2474
|
+
(lambda do
|
2475
|
+
@uri.merge(:authority => "bar@baz:bogus")
|
2476
|
+
end).should raise_error(Addressable::URI::InvalidURIError)
|
2477
|
+
end
|
2478
|
+
|
2479
|
+
it "should fail to merge with bogus parameters" do
|
2480
|
+
(lambda do
|
2481
|
+
@uri.merge(42)
|
2482
|
+
end).should raise_error(TypeError)
|
2483
|
+
end
|
2484
|
+
|
2485
|
+
it "should fail to merge with bogus parameters" do
|
2486
|
+
(lambda do
|
2487
|
+
@uri.merge("http://example.com/")
|
2488
|
+
end).should raise_error(TypeError)
|
2489
|
+
end
|
2490
|
+
|
2491
|
+
it "should fail to merge with both authority and subcomponents" do
|
2492
|
+
(lambda do
|
2493
|
+
@uri.merge(:authority => "foo:bar@baz:42", :port => "42")
|
2494
|
+
end).should raise_error(ArgumentError)
|
2495
|
+
end
|
2496
|
+
|
2497
|
+
it "should fail to merge with both userinfo and subcomponents" do
|
2498
|
+
(lambda do
|
2499
|
+
@uri.merge(:userinfo => "foo:bar", :user => "foo")
|
2500
|
+
end).should raise_error(ArgumentError)
|
2501
|
+
end
|
2502
|
+
|
2503
|
+
it "should be identical to its duplicate" do
|
2504
|
+
@uri.should == @uri.dup
|
2505
|
+
end
|
2506
|
+
end
|
2507
|
+
|
2508
|
+
describe Addressable::URI, "when parsed from " +
|
2509
|
+
"'http://example.com/?q&&x=b'" do
|
2510
|
+
before do
|
2511
|
+
@uri = Addressable::URI.parse("http://example.com/?q&&x=b")
|
2512
|
+
end
|
2513
|
+
|
2514
|
+
it "should have a query of 'q&&x=b'" do
|
2515
|
+
@uri.query.should == "q&&x=b"
|
2516
|
+
end
|
2517
|
+
|
2518
|
+
it "should have query_values of {'q' => true, 'x' => 'b'}" do
|
2519
|
+
@uri.query_values.should == {'q' => true, 'x' => 'b'}
|
2520
|
+
end
|
2521
|
+
end
|
2522
|
+
|
2523
|
+
describe Addressable::URI, "when parsed from " +
|
2524
|
+
"'http://example.com/?q=a+b'" do
|
2525
|
+
before do
|
2526
|
+
@uri = Addressable::URI.parse("http://example.com/?q=a+b")
|
2527
|
+
end
|
2528
|
+
|
2529
|
+
it "should have a query of 'q=a+b'" do
|
2530
|
+
@uri.query.should == "q=a+b"
|
2531
|
+
end
|
2532
|
+
|
2533
|
+
it "should have query_values of {'q' => 'a b'}" do
|
2534
|
+
@uri.query_values.should == {'q' => 'a b'}
|
2535
|
+
end
|
2536
|
+
end
|
2537
|
+
|
2538
|
+
describe Addressable::URI, "when parsed from " +
|
2539
|
+
"'http://example.com/?q=a%2bb'" do
|
2540
|
+
before do
|
2541
|
+
@uri = Addressable::URI.parse("http://example.com/?q=a%2bb")
|
2542
|
+
end
|
2543
|
+
|
2544
|
+
it "should have a query of 'q=a+b'" do
|
2545
|
+
@uri.query.should == "q=a%2bb"
|
2546
|
+
end
|
2547
|
+
|
2548
|
+
it "should have query_values of {'q' => 'a+b'}" do
|
2549
|
+
@uri.query_values.should == {'q' => 'a+b'}
|
2550
|
+
end
|
2551
|
+
end
|
2552
|
+
|
2553
|
+
describe Addressable::URI, "when parsed from " +
|
2554
|
+
"'http://example.com/?q='" do
|
2555
|
+
before do
|
2556
|
+
@uri = Addressable::URI.parse("http://example.com/?q=")
|
2557
|
+
end
|
2558
|
+
|
2559
|
+
it "should have a query of 'q='" do
|
2560
|
+
@uri.query.should == "q="
|
2561
|
+
end
|
2562
|
+
|
2563
|
+
it "should have query_values of {'q' => ''}" do
|
2564
|
+
@uri.query_values.should == {'q' => ''}
|
2565
|
+
end
|
2566
|
+
end
|
2567
|
+
|
2568
|
+
describe Addressable::URI, "when parsed from " +
|
2569
|
+
"'http://user@example.com'" do
|
2570
|
+
before do
|
2571
|
+
@uri = Addressable::URI.parse("http://user@example.com")
|
2572
|
+
end
|
2573
|
+
|
2574
|
+
it "should use the 'http' scheme" do
|
2575
|
+
@uri.scheme.should == "http"
|
2576
|
+
end
|
2577
|
+
|
2578
|
+
it "should have a username of 'user'" do
|
2579
|
+
@uri.user.should == "user"
|
2580
|
+
end
|
2581
|
+
|
2582
|
+
it "should have no password" do
|
2583
|
+
@uri.password.should == nil
|
2584
|
+
end
|
2585
|
+
|
2586
|
+
it "should have a userinfo of 'user'" do
|
2587
|
+
@uri.userinfo.should == "user"
|
2588
|
+
end
|
2589
|
+
|
2590
|
+
it "should have a normalized userinfo of 'user'" do
|
2591
|
+
@uri.normalized_userinfo.should == "user"
|
2592
|
+
end
|
2593
|
+
|
2594
|
+
it "should have a host of 'example.com'" do
|
2595
|
+
@uri.host.should == "example.com"
|
2596
|
+
end
|
2597
|
+
|
2598
|
+
it "should use port 80" do
|
2599
|
+
@uri.inferred_port.should == 80
|
2600
|
+
end
|
2601
|
+
|
2602
|
+
it "should have the correct username after assignment" do
|
2603
|
+
@uri.user = "newuser"
|
2604
|
+
@uri.user.should == "newuser"
|
2605
|
+
@uri.password.should == nil
|
2606
|
+
@uri.to_s.should == "http://newuser@example.com"
|
2607
|
+
end
|
2608
|
+
|
2609
|
+
it "should have the correct password after assignment" do
|
2610
|
+
@uri.password = "newpass"
|
2611
|
+
@uri.password.should == "newpass"
|
2612
|
+
@uri.to_s.should == "http://user:newpass@example.com"
|
2613
|
+
end
|
2614
|
+
|
2615
|
+
it "should have the correct userinfo segment after assignment" do
|
2616
|
+
@uri.userinfo = "newuser:newpass"
|
2617
|
+
@uri.userinfo.should == "newuser:newpass"
|
2618
|
+
@uri.user.should == "newuser"
|
2619
|
+
@uri.password.should == "newpass"
|
2620
|
+
@uri.host.should == "example.com"
|
2621
|
+
@uri.port.should == nil
|
2622
|
+
@uri.inferred_port.should == 80
|
2623
|
+
@uri.to_s.should == "http://newuser:newpass@example.com"
|
2624
|
+
end
|
2625
|
+
|
2626
|
+
it "should have the correct userinfo segment after nil assignment" do
|
2627
|
+
@uri.userinfo = nil
|
2628
|
+
@uri.userinfo.should == nil
|
2629
|
+
@uri.user.should == nil
|
2630
|
+
@uri.password.should == nil
|
2631
|
+
@uri.host.should == "example.com"
|
2632
|
+
@uri.port.should == nil
|
2633
|
+
@uri.inferred_port.should == 80
|
2634
|
+
@uri.to_s.should == "http://example.com"
|
2635
|
+
end
|
2636
|
+
|
2637
|
+
it "should have the correct authority segment after assignment" do
|
2638
|
+
@uri.authority = "newuser@example.com"
|
2639
|
+
@uri.authority.should == "newuser@example.com"
|
2640
|
+
@uri.user.should == "newuser"
|
2641
|
+
@uri.password.should == nil
|
2642
|
+
@uri.host.should == "example.com"
|
2643
|
+
@uri.port.should == nil
|
2644
|
+
@uri.inferred_port.should == 80
|
2645
|
+
@uri.to_s.should == "http://newuser@example.com"
|
2646
|
+
end
|
2647
|
+
|
2648
|
+
it "should raise an error after nil assignment of authority segment" do
|
2649
|
+
(lambda do
|
2650
|
+
# This would create an invalid URI
|
2651
|
+
@uri.authority = nil
|
2652
|
+
end).should raise_error
|
2653
|
+
end
|
2654
|
+
end
|
2655
|
+
|
2656
|
+
describe Addressable::URI, "when parsed from " +
|
2657
|
+
"'http://user:@example.com'" do
|
2658
|
+
before do
|
2659
|
+
@uri = Addressable::URI.parse("http://user:@example.com")
|
2660
|
+
end
|
2661
|
+
|
2662
|
+
it "should use the 'http' scheme" do
|
2663
|
+
@uri.scheme.should == "http"
|
2664
|
+
end
|
2665
|
+
|
2666
|
+
it "should have a username of 'user'" do
|
2667
|
+
@uri.user.should == "user"
|
2668
|
+
end
|
2669
|
+
|
2670
|
+
it "should have a password of ''" do
|
2671
|
+
@uri.password.should == ""
|
2672
|
+
end
|
2673
|
+
|
2674
|
+
it "should have a normalized userinfo of 'user:'" do
|
2675
|
+
@uri.normalized_userinfo.should == "user:"
|
2676
|
+
end
|
2677
|
+
|
2678
|
+
it "should have a host of 'example.com'" do
|
2679
|
+
@uri.host.should == "example.com"
|
2680
|
+
end
|
2681
|
+
|
2682
|
+
it "should use port 80" do
|
2683
|
+
@uri.inferred_port.should == 80
|
2684
|
+
end
|
2685
|
+
|
2686
|
+
it "should have the correct username after assignment" do
|
2687
|
+
@uri.user = "newuser"
|
2688
|
+
@uri.user.should == "newuser"
|
2689
|
+
@uri.password.should == ""
|
2690
|
+
@uri.to_s.should == "http://newuser:@example.com"
|
2691
|
+
end
|
2692
|
+
|
2693
|
+
it "should have the correct password after assignment" do
|
2694
|
+
@uri.password = "newpass"
|
2695
|
+
@uri.password.should == "newpass"
|
2696
|
+
@uri.to_s.should == "http://user:newpass@example.com"
|
2697
|
+
end
|
2698
|
+
|
2699
|
+
it "should have the correct authority segment after assignment" do
|
2700
|
+
@uri.authority = "newuser:@example.com"
|
2701
|
+
@uri.authority.should == "newuser:@example.com"
|
2702
|
+
@uri.user.should == "newuser"
|
2703
|
+
@uri.password.should == ""
|
2704
|
+
@uri.host.should == "example.com"
|
2705
|
+
@uri.port.should == nil
|
2706
|
+
@uri.inferred_port.should == 80
|
2707
|
+
@uri.to_s.should == "http://newuser:@example.com"
|
2708
|
+
end
|
2709
|
+
end
|
2710
|
+
|
2711
|
+
describe Addressable::URI, "when parsed from " +
|
2712
|
+
"'http://:pass@example.com'" do
|
2713
|
+
before do
|
2714
|
+
@uri = Addressable::URI.parse("http://:pass@example.com")
|
2715
|
+
end
|
2716
|
+
|
2717
|
+
it "should use the 'http' scheme" do
|
2718
|
+
@uri.scheme.should == "http"
|
2719
|
+
end
|
2720
|
+
|
2721
|
+
it "should have a username of ''" do
|
2722
|
+
@uri.user.should == ""
|
2723
|
+
end
|
2724
|
+
|
2725
|
+
it "should have a password of 'pass'" do
|
2726
|
+
@uri.password.should == "pass"
|
2727
|
+
end
|
2728
|
+
|
2729
|
+
it "should have a userinfo of ':pass'" do
|
2730
|
+
@uri.userinfo.should == ":pass"
|
2731
|
+
end
|
2732
|
+
|
2733
|
+
it "should have a normalized userinfo of ':pass'" do
|
2734
|
+
@uri.normalized_userinfo.should == ":pass"
|
2735
|
+
end
|
2736
|
+
|
2737
|
+
it "should have a host of 'example.com'" do
|
2738
|
+
@uri.host.should == "example.com"
|
2739
|
+
end
|
2740
|
+
|
2741
|
+
it "should use port 80" do
|
2742
|
+
@uri.inferred_port.should == 80
|
2743
|
+
end
|
2744
|
+
|
2745
|
+
it "should have the correct username after assignment" do
|
2746
|
+
@uri.user = "newuser"
|
2747
|
+
@uri.user.should == "newuser"
|
2748
|
+
@uri.password.should == "pass"
|
2749
|
+
@uri.to_s.should == "http://newuser:pass@example.com"
|
2750
|
+
end
|
2751
|
+
|
2752
|
+
it "should have the correct password after assignment" do
|
2753
|
+
@uri.password = "newpass"
|
2754
|
+
@uri.password.should == "newpass"
|
2755
|
+
@uri.user.should == ""
|
2756
|
+
@uri.to_s.should == "http://:newpass@example.com"
|
2757
|
+
end
|
2758
|
+
|
2759
|
+
it "should have the correct authority segment after assignment" do
|
2760
|
+
@uri.authority = ":newpass@example.com"
|
2761
|
+
@uri.authority.should == ":newpass@example.com"
|
2762
|
+
@uri.user.should == ""
|
2763
|
+
@uri.password.should == "newpass"
|
2764
|
+
@uri.host.should == "example.com"
|
2765
|
+
@uri.port.should == nil
|
2766
|
+
@uri.inferred_port.should == 80
|
2767
|
+
@uri.to_s.should == "http://:newpass@example.com"
|
2768
|
+
end
|
2769
|
+
end
|
2770
|
+
|
2771
|
+
describe Addressable::URI, "when parsed from " +
|
2772
|
+
"'http://:@example.com'" do
|
2773
|
+
before do
|
2774
|
+
@uri = Addressable::URI.parse("http://:@example.com")
|
2775
|
+
end
|
2776
|
+
|
2777
|
+
it "should use the 'http' scheme" do
|
2778
|
+
@uri.scheme.should == "http"
|
2779
|
+
end
|
2780
|
+
|
2781
|
+
it "should have a username of ''" do
|
2782
|
+
@uri.user.should == ""
|
2783
|
+
end
|
2784
|
+
|
2785
|
+
it "should have a password of ''" do
|
2786
|
+
@uri.password.should == ""
|
2787
|
+
end
|
2788
|
+
|
2789
|
+
it "should have a normalized userinfo of nil" do
|
2790
|
+
@uri.normalized_userinfo.should == nil
|
2791
|
+
end
|
2792
|
+
|
2793
|
+
it "should have a host of 'example.com'" do
|
2794
|
+
@uri.host.should == "example.com"
|
2795
|
+
end
|
2796
|
+
|
2797
|
+
it "should use port 80" do
|
2798
|
+
@uri.inferred_port.should == 80
|
2799
|
+
end
|
2800
|
+
|
2801
|
+
it "should have the correct username after assignment" do
|
2802
|
+
@uri.user = "newuser"
|
2803
|
+
@uri.user.should == "newuser"
|
2804
|
+
@uri.password.should == ""
|
2805
|
+
@uri.to_s.should == "http://newuser:@example.com"
|
2806
|
+
end
|
2807
|
+
|
2808
|
+
it "should have the correct password after assignment" do
|
2809
|
+
@uri.password = "newpass"
|
2810
|
+
@uri.password.should == "newpass"
|
2811
|
+
@uri.user.should == ""
|
2812
|
+
@uri.to_s.should == "http://:newpass@example.com"
|
2813
|
+
end
|
2814
|
+
|
2815
|
+
it "should have the correct authority segment after assignment" do
|
2816
|
+
@uri.authority = ":@newexample.com"
|
2817
|
+
@uri.authority.should == ":@newexample.com"
|
2818
|
+
@uri.user.should == ""
|
2819
|
+
@uri.password.should == ""
|
2820
|
+
@uri.host.should == "newexample.com"
|
2821
|
+
@uri.port.should == nil
|
2822
|
+
@uri.inferred_port.should == 80
|
2823
|
+
@uri.to_s.should == "http://:@newexample.com"
|
2824
|
+
end
|
2825
|
+
end
|
2826
|
+
|
2827
|
+
describe Addressable::URI, "when parsed from " +
|
2828
|
+
"'#example'" do
|
2829
|
+
before do
|
2830
|
+
@uri = Addressable::URI.parse("#example")
|
2831
|
+
end
|
2832
|
+
|
2833
|
+
it "should be considered relative" do
|
2834
|
+
@uri.should be_relative
|
2835
|
+
end
|
2836
|
+
|
2837
|
+
it "should have a host of nil" do
|
2838
|
+
@uri.host.should == nil
|
2839
|
+
end
|
2840
|
+
|
2841
|
+
it "should have a site of nil" do
|
2842
|
+
@uri.site.should == nil
|
2843
|
+
end
|
2844
|
+
|
2845
|
+
it "should have a normalized_site of nil" do
|
2846
|
+
@uri.normalized_site.should == nil
|
2847
|
+
end
|
2848
|
+
|
2849
|
+
it "should have a path of ''" do
|
2850
|
+
@uri.path.should == ""
|
2851
|
+
end
|
2852
|
+
|
2853
|
+
it "should have a query string of nil" do
|
2854
|
+
@uri.query.should == nil
|
2855
|
+
end
|
2856
|
+
|
2857
|
+
it "should have a fragment of 'example'" do
|
2858
|
+
@uri.fragment.should == "example"
|
2859
|
+
end
|
2860
|
+
end
|
2861
|
+
|
2862
|
+
describe Addressable::URI, "when parsed from " +
|
2863
|
+
"the network-path reference '//example.com/'" do
|
2864
|
+
before do
|
2865
|
+
@uri = Addressable::URI.parse("//example.com/")
|
2866
|
+
end
|
2867
|
+
|
2868
|
+
it "should be considered relative" do
|
2869
|
+
@uri.should be_relative
|
2870
|
+
end
|
2871
|
+
|
2872
|
+
it "should have a host of 'example.com'" do
|
2873
|
+
@uri.host.should == "example.com"
|
2874
|
+
end
|
2875
|
+
|
2876
|
+
it "should have a path of '/'" do
|
2877
|
+
@uri.path.should == "/"
|
2878
|
+
end
|
2879
|
+
|
2880
|
+
it "should raise an error if routing is attempted" do
|
2881
|
+
(lambda do
|
2882
|
+
@uri.route_to("http://example.com/")
|
2883
|
+
end).should raise_error(ArgumentError, /\/\/example.com\//)
|
2884
|
+
(lambda do
|
2885
|
+
@uri.route_from("http://example.com/")
|
2886
|
+
end).should raise_error(ArgumentError, /\/\/example.com\//)
|
2887
|
+
end
|
2888
|
+
end
|
2889
|
+
|
2890
|
+
describe Addressable::URI, "when parsed from " +
|
2891
|
+
"'feed://http://example.com/'" do
|
2892
|
+
before do
|
2893
|
+
@uri = Addressable::URI.parse("feed://http://example.com/")
|
2894
|
+
end
|
2895
|
+
|
2896
|
+
it "should have a host of 'http'" do
|
2897
|
+
@uri.host.should == "http"
|
2898
|
+
end
|
2899
|
+
|
2900
|
+
it "should have a path of '//example.com/'" do
|
2901
|
+
@uri.path.should == "//example.com/"
|
2902
|
+
end
|
2903
|
+
end
|
2904
|
+
|
2905
|
+
describe Addressable::URI, "when parsed from " +
|
2906
|
+
"'feed:http://example.com/'" do
|
2907
|
+
before do
|
2908
|
+
@uri = Addressable::URI.parse("feed:http://example.com/")
|
2909
|
+
end
|
2910
|
+
|
2911
|
+
it "should have a path of 'http://example.com/'" do
|
2912
|
+
@uri.path.should == "http://example.com/"
|
2913
|
+
end
|
2914
|
+
|
2915
|
+
it "should normalize to 'http://example.com/'" do
|
2916
|
+
@uri.normalize.to_s.should == "http://example.com/"
|
2917
|
+
@uri.normalize!.to_s.should == "http://example.com/"
|
2918
|
+
end
|
2919
|
+
end
|
2920
|
+
|
2921
|
+
describe Addressable::URI, "when parsed from " +
|
2922
|
+
"'example://a/b/c/%7Bfoo%7D'" do
|
2923
|
+
before do
|
2924
|
+
@uri = Addressable::URI.parse("example://a/b/c/%7Bfoo%7D")
|
2925
|
+
end
|
2926
|
+
|
2927
|
+
# Section 6.2.2 of RFC 3986
|
2928
|
+
it "should be equivalent to eXAMPLE://a/./b/../b/%63/%7bfoo%7d" do
|
2929
|
+
@uri.should ==
|
2930
|
+
Addressable::URI.parse("eXAMPLE://a/./b/../b/%63/%7bfoo%7d")
|
2931
|
+
end
|
2932
|
+
end
|
2933
|
+
|
2934
|
+
describe Addressable::URI, "when parsed from " +
|
2935
|
+
"'http://example.com/indirect/path/./to/../resource/'" do
|
2936
|
+
before do
|
2937
|
+
@uri = Addressable::URI.parse(
|
2938
|
+
"http://example.com/indirect/path/./to/../resource/")
|
2939
|
+
end
|
2940
|
+
|
2941
|
+
it "should use the 'http' scheme" do
|
2942
|
+
@uri.scheme.should == "http"
|
2943
|
+
end
|
2944
|
+
|
2945
|
+
it "should have a host of 'example.com'" do
|
2946
|
+
@uri.host.should == "example.com"
|
2947
|
+
end
|
2948
|
+
|
2949
|
+
it "should use port 80" do
|
2950
|
+
@uri.inferred_port.should == 80
|
2951
|
+
end
|
2952
|
+
|
2953
|
+
it "should have a path of '/indirect/path/./to/../resource/'" do
|
2954
|
+
@uri.path.should == "/indirect/path/./to/../resource/"
|
2955
|
+
end
|
2956
|
+
|
2957
|
+
# Section 6.2.2.3 of RFC 3986
|
2958
|
+
it "should have a normalized path of '/indirect/path/resource/'" do
|
2959
|
+
@uri.normalize.path.should == "/indirect/path/resource/"
|
2960
|
+
@uri.normalize!.path.should == "/indirect/path/resource/"
|
2961
|
+
end
|
2962
|
+
end
|
2963
|
+
|
2964
|
+
describe Addressable::URI, "when parsed from " +
|
2965
|
+
"'http://under_score.example.com/'" do
|
2966
|
+
it "should not cause an error" do
|
2967
|
+
(lambda do
|
2968
|
+
Addressable::URI.parse("http://under_score.example.com/")
|
2969
|
+
end).should_not raise_error
|
2970
|
+
end
|
2971
|
+
end
|
2972
|
+
|
2973
|
+
describe Addressable::URI, "when parsed from " +
|
2974
|
+
"'./this:that'" do
|
2975
|
+
before do
|
2976
|
+
@uri = Addressable::URI.parse("./this:that")
|
2977
|
+
end
|
2978
|
+
|
2979
|
+
it "should be considered relative" do
|
2980
|
+
@uri.should be_relative
|
2981
|
+
end
|
2982
|
+
|
2983
|
+
it "should have no scheme" do
|
2984
|
+
@uri.scheme.should == nil
|
2985
|
+
end
|
2986
|
+
end
|
2987
|
+
|
2988
|
+
describe Addressable::URI, "when parsed from " +
|
2989
|
+
"'this:that'" do
|
2990
|
+
before do
|
2991
|
+
@uri = Addressable::URI.parse("this:that")
|
2992
|
+
end
|
2993
|
+
|
2994
|
+
it "should be considered absolute" do
|
2995
|
+
@uri.should be_absolute
|
2996
|
+
end
|
2997
|
+
|
2998
|
+
it "should have a scheme of 'this'" do
|
2999
|
+
@uri.scheme.should == "this"
|
3000
|
+
end
|
3001
|
+
end
|
3002
|
+
|
3003
|
+
describe Addressable::URI, "when parsed from '?'" do
|
3004
|
+
before do
|
3005
|
+
@uri = Addressable::URI.parse("?")
|
3006
|
+
end
|
3007
|
+
|
3008
|
+
it "should have the correct subscript notation query values" do
|
3009
|
+
@uri.query_values.should == {}
|
3010
|
+
@uri.query_values(:notation => :subscript).should == {}
|
3011
|
+
end
|
3012
|
+
|
3013
|
+
it "should have the correct dot notation query values" do
|
3014
|
+
@uri.query_values(:notation => :dot).should == {}
|
3015
|
+
end
|
3016
|
+
|
3017
|
+
it "should have the correct flat notation query values" do
|
3018
|
+
@uri.query_values(:notation => :flat).should == {}
|
3019
|
+
end
|
3020
|
+
end
|
3021
|
+
|
3022
|
+
describe Addressable::URI, "when parsed from '?one=1&two=2&three=3'" do
|
3023
|
+
before do
|
3024
|
+
@uri = Addressable::URI.parse("?one=1&two=2&three=3")
|
3025
|
+
end
|
3026
|
+
|
3027
|
+
it "should have the correct query values" do
|
3028
|
+
@uri.query_values.should == {"one" => "1", "two" => "2", "three" => "3"}
|
3029
|
+
end
|
3030
|
+
|
3031
|
+
it "should raise an error for invalid query value notations" do
|
3032
|
+
(lambda do
|
3033
|
+
@uri.query_values(:notation => :bogus)
|
3034
|
+
end).should raise_error(ArgumentError)
|
3035
|
+
end
|
3036
|
+
end
|
3037
|
+
|
3038
|
+
describe Addressable::URI, "when parsed from '?one[two][three]=four'" do
|
3039
|
+
before do
|
3040
|
+
@uri = Addressable::URI.parse("?one[two][three]=four")
|
3041
|
+
end
|
3042
|
+
|
3043
|
+
it "should have the correct query values" do
|
3044
|
+
@uri.query_values.should == {"one" => {"two" => {"three" => "four"}}}
|
3045
|
+
end
|
3046
|
+
|
3047
|
+
it "should have the correct flat notation query values" do
|
3048
|
+
@uri.query_values(:notation => :flat).should == {
|
3049
|
+
"one[two][three]" => "four"
|
3050
|
+
}
|
3051
|
+
end
|
3052
|
+
end
|
3053
|
+
|
3054
|
+
describe Addressable::URI, "when parsed from '?one.two.three=four'" do
|
3055
|
+
before do
|
3056
|
+
@uri = Addressable::URI.parse("?one.two.three=four")
|
3057
|
+
end
|
3058
|
+
|
3059
|
+
it "should have the correct dot notation query values" do
|
3060
|
+
@uri.query_values(:notation => :dot).should == {
|
3061
|
+
"one" => {"two" => {"three" => "four"}}
|
3062
|
+
}
|
3063
|
+
end
|
3064
|
+
|
3065
|
+
it "should have the correct flat notation query values" do
|
3066
|
+
@uri.query_values(:notation => :flat).should == {
|
3067
|
+
"one.two.three" => "four"
|
3068
|
+
}
|
3069
|
+
end
|
3070
|
+
end
|
3071
|
+
|
3072
|
+
describe Addressable::URI, "when parsed from " +
|
3073
|
+
"'?one[two][three]=four&one[two][five]=six'" do
|
3074
|
+
before do
|
3075
|
+
@uri = Addressable::URI.parse("?one[two][three]=four&one[two][five]=six")
|
3076
|
+
end
|
3077
|
+
|
3078
|
+
it "should have the correct dot notation query values" do
|
3079
|
+
@uri.query_values(:notation => :subscript).should == {
|
3080
|
+
"one" => {"two" => {"three" => "four", "five" => "six"}}
|
3081
|
+
}
|
3082
|
+
end
|
3083
|
+
|
3084
|
+
it "should have the correct flat notation query values" do
|
3085
|
+
@uri.query_values(:notation => :flat).should == {
|
3086
|
+
"one[two][three]" => "four",
|
3087
|
+
"one[two][five]" => "six"
|
3088
|
+
}
|
3089
|
+
end
|
3090
|
+
end
|
3091
|
+
|
3092
|
+
describe Addressable::URI, "when parsed from " +
|
3093
|
+
"'?one.two.three=four&one.two.five=six'" do
|
3094
|
+
before do
|
3095
|
+
@uri = Addressable::URI.parse("?one.two.three=four&one.two.five=six")
|
3096
|
+
end
|
3097
|
+
|
3098
|
+
it "should have the correct dot notation query values" do
|
3099
|
+
@uri.query_values(:notation => :dot).should == {
|
3100
|
+
"one" => {"two" => {"three" => "four", "five" => "six"}}
|
3101
|
+
}
|
3102
|
+
end
|
3103
|
+
|
3104
|
+
it "should have the correct flat notation query values" do
|
3105
|
+
@uri.query_values(:notation => :flat).should == {
|
3106
|
+
"one.two.three" => "four",
|
3107
|
+
"one.two.five" => "six"
|
3108
|
+
}
|
3109
|
+
end
|
3110
|
+
end
|
3111
|
+
|
3112
|
+
describe Addressable::URI, "when parsed from " +
|
3113
|
+
"'?one[two][three][]=four&one[two][three][]=five'" do
|
3114
|
+
before do
|
3115
|
+
@uri = Addressable::URI.parse(
|
3116
|
+
"?one[two][three][]=four&one[two][three][]=five"
|
3117
|
+
)
|
3118
|
+
end
|
3119
|
+
|
3120
|
+
it "should have the correct subscript notation query values" do
|
3121
|
+
@uri.query_values(:notation => :subscript).should == {
|
3122
|
+
"one" => {"two" => {"three" => ["four", "five"]}}
|
3123
|
+
}
|
3124
|
+
end
|
3125
|
+
|
3126
|
+
it "should raise an error if a key is repeated in the flat notation" do
|
3127
|
+
(lambda do
|
3128
|
+
@uri.query_values(:notation => :flat)
|
3129
|
+
end).should raise_error(ArgumentError)
|
3130
|
+
end
|
3131
|
+
end
|
3132
|
+
|
3133
|
+
describe Addressable::URI, "when parsed from " +
|
3134
|
+
"'?one[two][three][0]=four&one[two][three][1]=five'" do
|
3135
|
+
before do
|
3136
|
+
@uri = Addressable::URI.parse(
|
3137
|
+
"?one[two][three][0]=four&one[two][three][1]=five"
|
3138
|
+
)
|
3139
|
+
end
|
3140
|
+
|
3141
|
+
it "should have the correct subscript notation query values" do
|
3142
|
+
@uri.query_values(:notation => :subscript).should == {
|
3143
|
+
"one" => {"two" => {"three" => ["four", "five"]}}
|
3144
|
+
}
|
3145
|
+
end
|
3146
|
+
end
|
3147
|
+
|
3148
|
+
describe Addressable::URI, "when parsed from " +
|
3149
|
+
"'http://www.詹姆斯.com/'" do
|
3150
|
+
before do
|
3151
|
+
@uri = Addressable::URI.parse("http://www.詹姆斯.com/")
|
3152
|
+
end
|
3153
|
+
|
3154
|
+
it "should be equivalent to 'http://www.xn--8ws00zhy3a.com/'" do
|
3155
|
+
@uri.should ==
|
3156
|
+
Addressable::URI.parse("http://www.xn--8ws00zhy3a.com/")
|
3157
|
+
end
|
3158
|
+
|
3159
|
+
it "should not have domain name encoded during normalization" do
|
3160
|
+
Addressable::URI.normalized_encode(@uri.to_s).should ==
|
3161
|
+
"http://www.詹姆斯.com/"
|
3162
|
+
end
|
3163
|
+
end
|
3164
|
+
|
3165
|
+
describe Addressable::URI, "when parsed from " +
|
3166
|
+
"'http://www.詹姆斯.com/ some spaces /'" do
|
3167
|
+
before do
|
3168
|
+
@uri = Addressable::URI.parse("http://www.詹姆斯.com/ some spaces /")
|
3169
|
+
end
|
3170
|
+
|
3171
|
+
it "should be equivalent to " +
|
3172
|
+
"'http://www.xn--8ws00zhy3a.com/%20some%20spaces%20/'" do
|
3173
|
+
@uri.should ==
|
3174
|
+
Addressable::URI.parse(
|
3175
|
+
"http://www.xn--8ws00zhy3a.com/%20some%20spaces%20/")
|
3176
|
+
end
|
3177
|
+
|
3178
|
+
it "should not have domain name encoded during normalization" do
|
3179
|
+
Addressable::URI.normalized_encode(@uri.to_s).should ==
|
3180
|
+
"http://www.詹姆斯.com/%20some%20spaces%20/"
|
3181
|
+
end
|
3182
|
+
end
|
3183
|
+
|
3184
|
+
describe Addressable::URI, "when parsed from " +
|
3185
|
+
"'http://www.xn--8ws00zhy3a.com/'" do
|
3186
|
+
before do
|
3187
|
+
@uri = Addressable::URI.parse("http://www.xn--8ws00zhy3a.com/")
|
3188
|
+
end
|
3189
|
+
|
3190
|
+
it "should be displayed as http://www.詹姆斯.com/" do
|
3191
|
+
@uri.display_uri.to_s.should == "http://www.詹姆斯.com/"
|
3192
|
+
end
|
3193
|
+
|
3194
|
+
it "should properly force the encoding" do
|
3195
|
+
display_string = @uri.display_uri.to_str
|
3196
|
+
display_string.should == "http://www.詹姆斯.com/"
|
3197
|
+
if display_string.respond_to?(:encoding)
|
3198
|
+
display_string.encoding.to_s.should == Encoding::UTF_8.to_s
|
3199
|
+
end
|
3200
|
+
end
|
3201
|
+
end
|
3202
|
+
|
3203
|
+
describe Addressable::URI, "when parsed from " +
|
3204
|
+
"'http://www.詹姆斯.com/atomtests/iri/詹.html'" do
|
3205
|
+
before do
|
3206
|
+
@uri = Addressable::URI.parse("http://www.詹姆斯.com/atomtests/iri/詹.html")
|
3207
|
+
end
|
3208
|
+
|
3209
|
+
it "should normalize to " +
|
3210
|
+
"http://www.xn--8ws00zhy3a.com/atomtests/iri/%E8%A9%B9.html" do
|
3211
|
+
@uri.normalize.to_s.should ==
|
3212
|
+
"http://www.xn--8ws00zhy3a.com/atomtests/iri/%E8%A9%B9.html"
|
3213
|
+
@uri.normalize!.to_s.should ==
|
3214
|
+
"http://www.xn--8ws00zhy3a.com/atomtests/iri/%E8%A9%B9.html"
|
3215
|
+
end
|
3216
|
+
end
|
3217
|
+
|
3218
|
+
describe Addressable::URI, "when parsed from a percent-encoded IRI" do
|
3219
|
+
before do
|
3220
|
+
@uri = Addressable::URI.parse(
|
3221
|
+
"http://www.%E3%81%BB%E3%82%93%E3%81%A8%E3%81%86%E3%81%AB%E3%81%AA" +
|
3222
|
+
"%E3%81%8C%E3%81%84%E3%82%8F%E3%81%91%E3%81%AE%E3%82%8F%E3%81%8B%E3" +
|
3223
|
+
"%82%89%E3%81%AA%E3%81%84%E3%81%A9%E3%82%81%E3%81%84%E3%82%93%E3%82" +
|
3224
|
+
"%81%E3%81%84%E3%81%AE%E3%82%89%E3%81%B9%E3%82%8B%E3%81%BE%E3%81%A0" +
|
3225
|
+
"%E3%81%AA%E3%81%8C%E3%81%8F%E3%81%97%E3%81%AA%E3%81%84%E3%81%A8%E3" +
|
3226
|
+
"%81%9F%E3%82%8A%E3%81%AA%E3%81%84.w3.mag.keio.ac.jp"
|
3227
|
+
)
|
3228
|
+
end
|
3229
|
+
|
3230
|
+
it "should normalize to something sane" do
|
3231
|
+
@uri.normalize.to_s.should ==
|
3232
|
+
"http://www.xn--n8jaaaaai5bhf7as8fsfk3jnknefdde3f" +
|
3233
|
+
"g11amb5gzdb4wi9bya3kc6lra.w3.mag.keio.ac.jp/"
|
3234
|
+
@uri.normalize!.to_s.should ==
|
3235
|
+
"http://www.xn--n8jaaaaai5bhf7as8fsfk3jnknefdde3f" +
|
3236
|
+
"g11amb5gzdb4wi9bya3kc6lra.w3.mag.keio.ac.jp/"
|
3237
|
+
end
|
3238
|
+
end
|
3239
|
+
|
3240
|
+
describe Addressable::URI, "with a base uri of 'http://a/b/c/d;p?q'" do
|
3241
|
+
before do
|
3242
|
+
@uri = Addressable::URI.parse("http://a/b/c/d;p?q")
|
3243
|
+
end
|
3244
|
+
|
3245
|
+
# Section 5.4.1 of RFC 3986
|
3246
|
+
it "when joined with 'g:h' should resolve to g:h" do
|
3247
|
+
(@uri + "g:h").to_s.should == "g:h"
|
3248
|
+
Addressable::URI.join(@uri, "g:h").to_s.should == "g:h"
|
3249
|
+
end
|
3250
|
+
|
3251
|
+
# Section 5.4.1 of RFC 3986
|
3252
|
+
it "when joined with 'g' should resolve to http://a/b/c/g" do
|
3253
|
+
(@uri + "g").to_s.should == "http://a/b/c/g"
|
3254
|
+
Addressable::URI.join(@uri.to_s, "g").to_s.should == "http://a/b/c/g"
|
3255
|
+
end
|
3256
|
+
|
3257
|
+
# Section 5.4.1 of RFC 3986
|
3258
|
+
it "when joined with './g' should resolve to http://a/b/c/g" do
|
3259
|
+
(@uri + "./g").to_s.should == "http://a/b/c/g"
|
3260
|
+
Addressable::URI.join(@uri.to_s, "./g").to_s.should == "http://a/b/c/g"
|
3261
|
+
end
|
3262
|
+
|
3263
|
+
# Section 5.4.1 of RFC 3986
|
3264
|
+
it "when joined with 'g/' should resolve to http://a/b/c/g/" do
|
3265
|
+
(@uri + "g/").to_s.should == "http://a/b/c/g/"
|
3266
|
+
Addressable::URI.join(@uri.to_s, "g/").to_s.should == "http://a/b/c/g/"
|
3267
|
+
end
|
3268
|
+
|
3269
|
+
# Section 5.4.1 of RFC 3986
|
3270
|
+
it "when joined with '/g' should resolve to http://a/g" do
|
3271
|
+
(@uri + "/g").to_s.should == "http://a/g"
|
3272
|
+
Addressable::URI.join(@uri.to_s, "/g").to_s.should == "http://a/g"
|
3273
|
+
end
|
3274
|
+
|
3275
|
+
# Section 5.4.1 of RFC 3986
|
3276
|
+
it "when joined with '//g' should resolve to http://g" do
|
3277
|
+
(@uri + "//g").to_s.should == "http://g"
|
3278
|
+
Addressable::URI.join(@uri.to_s, "//g").to_s.should == "http://g"
|
3279
|
+
end
|
3280
|
+
|
3281
|
+
# Section 5.4.1 of RFC 3986
|
3282
|
+
it "when joined with '?y' should resolve to http://a/b/c/d;p?y" do
|
3283
|
+
(@uri + "?y").to_s.should == "http://a/b/c/d;p?y"
|
3284
|
+
Addressable::URI.join(@uri.to_s, "?y").to_s.should == "http://a/b/c/d;p?y"
|
3285
|
+
end
|
3286
|
+
|
3287
|
+
# Section 5.4.1 of RFC 3986
|
3288
|
+
it "when joined with 'g?y' should resolve to http://a/b/c/g?y" do
|
3289
|
+
(@uri + "g?y").to_s.should == "http://a/b/c/g?y"
|
3290
|
+
Addressable::URI.join(@uri.to_s, "g?y").to_s.should == "http://a/b/c/g?y"
|
3291
|
+
end
|
3292
|
+
|
3293
|
+
# Section 5.4.1 of RFC 3986
|
3294
|
+
it "when joined with '#s' should resolve to http://a/b/c/d;p?q#s" do
|
3295
|
+
(@uri + "#s").to_s.should == "http://a/b/c/d;p?q#s"
|
3296
|
+
Addressable::URI.join(@uri.to_s, "#s").to_s.should ==
|
3297
|
+
"http://a/b/c/d;p?q#s"
|
3298
|
+
end
|
3299
|
+
|
3300
|
+
# Section 5.4.1 of RFC 3986
|
3301
|
+
it "when joined with 'g#s' should resolve to http://a/b/c/g#s" do
|
3302
|
+
(@uri + "g#s").to_s.should == "http://a/b/c/g#s"
|
3303
|
+
Addressable::URI.join(@uri.to_s, "g#s").to_s.should == "http://a/b/c/g#s"
|
3304
|
+
end
|
3305
|
+
|
3306
|
+
# Section 5.4.1 of RFC 3986
|
3307
|
+
it "when joined with 'g?y#s' should resolve to http://a/b/c/g?y#s" do
|
3308
|
+
(@uri + "g?y#s").to_s.should == "http://a/b/c/g?y#s"
|
3309
|
+
Addressable::URI.join(
|
3310
|
+
@uri.to_s, "g?y#s").to_s.should == "http://a/b/c/g?y#s"
|
3311
|
+
end
|
3312
|
+
|
3313
|
+
# Section 5.4.1 of RFC 3986
|
3314
|
+
it "when joined with ';x' should resolve to http://a/b/c/;x" do
|
3315
|
+
(@uri + ";x").to_s.should == "http://a/b/c/;x"
|
3316
|
+
Addressable::URI.join(@uri.to_s, ";x").to_s.should == "http://a/b/c/;x"
|
3317
|
+
end
|
3318
|
+
|
3319
|
+
# Section 5.4.1 of RFC 3986
|
3320
|
+
it "when joined with 'g;x' should resolve to http://a/b/c/g;x" do
|
3321
|
+
(@uri + "g;x").to_s.should == "http://a/b/c/g;x"
|
3322
|
+
Addressable::URI.join(@uri.to_s, "g;x").to_s.should == "http://a/b/c/g;x"
|
3323
|
+
end
|
3324
|
+
|
3325
|
+
# Section 5.4.1 of RFC 3986
|
3326
|
+
it "when joined with 'g;x?y#s' should resolve to http://a/b/c/g;x?y#s" do
|
3327
|
+
(@uri + "g;x?y#s").to_s.should == "http://a/b/c/g;x?y#s"
|
3328
|
+
Addressable::URI.join(
|
3329
|
+
@uri.to_s, "g;x?y#s").to_s.should == "http://a/b/c/g;x?y#s"
|
3330
|
+
end
|
3331
|
+
|
3332
|
+
# Section 5.4.1 of RFC 3986
|
3333
|
+
it "when joined with '' should resolve to http://a/b/c/d;p?q" do
|
3334
|
+
(@uri + "").to_s.should == "http://a/b/c/d;p?q"
|
3335
|
+
Addressable::URI.join(@uri.to_s, "").to_s.should == "http://a/b/c/d;p?q"
|
3336
|
+
end
|
3337
|
+
|
3338
|
+
# Section 5.4.1 of RFC 3986
|
3339
|
+
it "when joined with '.' should resolve to http://a/b/c/" do
|
3340
|
+
(@uri + ".").to_s.should == "http://a/b/c/"
|
3341
|
+
Addressable::URI.join(@uri.to_s, ".").to_s.should == "http://a/b/c/"
|
3342
|
+
end
|
3343
|
+
|
3344
|
+
# Section 5.4.1 of RFC 3986
|
3345
|
+
it "when joined with './' should resolve to http://a/b/c/" do
|
3346
|
+
(@uri + "./").to_s.should == "http://a/b/c/"
|
3347
|
+
Addressable::URI.join(@uri.to_s, "./").to_s.should == "http://a/b/c/"
|
3348
|
+
end
|
3349
|
+
|
3350
|
+
# Section 5.4.1 of RFC 3986
|
3351
|
+
it "when joined with '..' should resolve to http://a/b/" do
|
3352
|
+
(@uri + "..").to_s.should == "http://a/b/"
|
3353
|
+
Addressable::URI.join(@uri.to_s, "..").to_s.should == "http://a/b/"
|
3354
|
+
end
|
3355
|
+
|
3356
|
+
# Section 5.4.1 of RFC 3986
|
3357
|
+
it "when joined with '../' should resolve to http://a/b/" do
|
3358
|
+
(@uri + "../").to_s.should == "http://a/b/"
|
3359
|
+
Addressable::URI.join(@uri.to_s, "../").to_s.should == "http://a/b/"
|
3360
|
+
end
|
3361
|
+
|
3362
|
+
# Section 5.4.1 of RFC 3986
|
3363
|
+
it "when joined with '../g' should resolve to http://a/b/g" do
|
3364
|
+
(@uri + "../g").to_s.should == "http://a/b/g"
|
3365
|
+
Addressable::URI.join(@uri.to_s, "../g").to_s.should == "http://a/b/g"
|
3366
|
+
end
|
3367
|
+
|
3368
|
+
# Section 5.4.1 of RFC 3986
|
3369
|
+
it "when joined with '../..' should resolve to http://a/" do
|
3370
|
+
(@uri + "../..").to_s.should == "http://a/"
|
3371
|
+
Addressable::URI.join(@uri.to_s, "../..").to_s.should == "http://a/"
|
3372
|
+
end
|
3373
|
+
|
3374
|
+
# Section 5.4.1 of RFC 3986
|
3375
|
+
it "when joined with '../../' should resolve to http://a/" do
|
3376
|
+
(@uri + "../../").to_s.should == "http://a/"
|
3377
|
+
Addressable::URI.join(@uri.to_s, "../../").to_s.should == "http://a/"
|
3378
|
+
end
|
3379
|
+
|
3380
|
+
# Section 5.4.1 of RFC 3986
|
3381
|
+
it "when joined with '../../g' should resolve to http://a/g" do
|
3382
|
+
(@uri + "../../g").to_s.should == "http://a/g"
|
3383
|
+
Addressable::URI.join(@uri.to_s, "../../g").to_s.should == "http://a/g"
|
3384
|
+
end
|
3385
|
+
|
3386
|
+
# Section 5.4.2 of RFC 3986
|
3387
|
+
it "when joined with '../../../g' should resolve to http://a/g" do
|
3388
|
+
(@uri + "../../../g").to_s.should == "http://a/g"
|
3389
|
+
Addressable::URI.join(@uri.to_s, "../../../g").to_s.should == "http://a/g"
|
3390
|
+
end
|
3391
|
+
|
3392
|
+
it "when joined with '../.././../g' should resolve to http://a/g" do
|
3393
|
+
(@uri + "../.././../g").to_s.should == "http://a/g"
|
3394
|
+
Addressable::URI.join(@uri.to_s, "../.././../g").to_s.should ==
|
3395
|
+
"http://a/g"
|
3396
|
+
end
|
3397
|
+
|
3398
|
+
# Section 5.4.2 of RFC 3986
|
3399
|
+
it "when joined with '../../../../g' should resolve to http://a/g" do
|
3400
|
+
(@uri + "../../../../g").to_s.should == "http://a/g"
|
3401
|
+
Addressable::URI.join(
|
3402
|
+
@uri.to_s, "../../../../g").to_s.should == "http://a/g"
|
3403
|
+
end
|
3404
|
+
|
3405
|
+
# Section 5.4.2 of RFC 3986
|
3406
|
+
it "when joined with '/./g' should resolve to http://a/g" do
|
3407
|
+
(@uri + "/./g").to_s.should == "http://a/g"
|
3408
|
+
Addressable::URI.join(@uri.to_s, "/./g").to_s.should == "http://a/g"
|
3409
|
+
end
|
3410
|
+
|
3411
|
+
# Section 5.4.2 of RFC 3986
|
3412
|
+
it "when joined with '/../g' should resolve to http://a/g" do
|
3413
|
+
(@uri + "/../g").to_s.should == "http://a/g"
|
3414
|
+
Addressable::URI.join(@uri.to_s, "/../g").to_s.should == "http://a/g"
|
3415
|
+
end
|
3416
|
+
|
3417
|
+
# Section 5.4.2 of RFC 3986
|
3418
|
+
it "when joined with 'g.' should resolve to http://a/b/c/g." do
|
3419
|
+
(@uri + "g.").to_s.should == "http://a/b/c/g."
|
3420
|
+
Addressable::URI.join(@uri.to_s, "g.").to_s.should == "http://a/b/c/g."
|
3421
|
+
end
|
3422
|
+
|
3423
|
+
# Section 5.4.2 of RFC 3986
|
3424
|
+
it "when joined with '.g' should resolve to http://a/b/c/.g" do
|
3425
|
+
(@uri + ".g").to_s.should == "http://a/b/c/.g"
|
3426
|
+
Addressable::URI.join(@uri.to_s, ".g").to_s.should == "http://a/b/c/.g"
|
3427
|
+
end
|
3428
|
+
|
3429
|
+
# Section 5.4.2 of RFC 3986
|
3430
|
+
it "when joined with 'g..' should resolve to http://a/b/c/g.." do
|
3431
|
+
(@uri + "g..").to_s.should == "http://a/b/c/g.."
|
3432
|
+
Addressable::URI.join(@uri.to_s, "g..").to_s.should == "http://a/b/c/g.."
|
3433
|
+
end
|
3434
|
+
|
3435
|
+
# Section 5.4.2 of RFC 3986
|
3436
|
+
it "when joined with '..g' should resolve to http://a/b/c/..g" do
|
3437
|
+
(@uri + "..g").to_s.should == "http://a/b/c/..g"
|
3438
|
+
Addressable::URI.join(@uri.to_s, "..g").to_s.should == "http://a/b/c/..g"
|
3439
|
+
end
|
3440
|
+
|
3441
|
+
# Section 5.4.2 of RFC 3986
|
3442
|
+
it "when joined with './../g' should resolve to http://a/b/g" do
|
3443
|
+
(@uri + "./../g").to_s.should == "http://a/b/g"
|
3444
|
+
Addressable::URI.join(@uri.to_s, "./../g").to_s.should == "http://a/b/g"
|
3445
|
+
end
|
3446
|
+
|
3447
|
+
# Section 5.4.2 of RFC 3986
|
3448
|
+
it "when joined with './g/.' should resolve to http://a/b/c/g/" do
|
3449
|
+
(@uri + "./g/.").to_s.should == "http://a/b/c/g/"
|
3450
|
+
Addressable::URI.join(@uri.to_s, "./g/.").to_s.should == "http://a/b/c/g/"
|
3451
|
+
end
|
3452
|
+
|
3453
|
+
# Section 5.4.2 of RFC 3986
|
3454
|
+
it "when joined with 'g/./h' should resolve to http://a/b/c/g/h" do
|
3455
|
+
(@uri + "g/./h").to_s.should == "http://a/b/c/g/h"
|
3456
|
+
Addressable::URI.join(@uri.to_s, "g/./h").to_s.should == "http://a/b/c/g/h"
|
3457
|
+
end
|
3458
|
+
|
3459
|
+
# Section 5.4.2 of RFC 3986
|
3460
|
+
it "when joined with 'g/../h' should resolve to http://a/b/c/h" do
|
3461
|
+
(@uri + "g/../h").to_s.should == "http://a/b/c/h"
|
3462
|
+
Addressable::URI.join(@uri.to_s, "g/../h").to_s.should == "http://a/b/c/h"
|
3463
|
+
end
|
3464
|
+
|
3465
|
+
# Section 5.4.2 of RFC 3986
|
3466
|
+
it "when joined with 'g;x=1/./y' " +
|
3467
|
+
"should resolve to http://a/b/c/g;x=1/y" do
|
3468
|
+
(@uri + "g;x=1/./y").to_s.should == "http://a/b/c/g;x=1/y"
|
3469
|
+
Addressable::URI.join(
|
3470
|
+
@uri.to_s, "g;x=1/./y").to_s.should == "http://a/b/c/g;x=1/y"
|
3471
|
+
end
|
3472
|
+
|
3473
|
+
# Section 5.4.2 of RFC 3986
|
3474
|
+
it "when joined with 'g;x=1/../y' should resolve to http://a/b/c/y" do
|
3475
|
+
(@uri + "g;x=1/../y").to_s.should == "http://a/b/c/y"
|
3476
|
+
Addressable::URI.join(
|
3477
|
+
@uri.to_s, "g;x=1/../y").to_s.should == "http://a/b/c/y"
|
3478
|
+
end
|
3479
|
+
|
3480
|
+
# Section 5.4.2 of RFC 3986
|
3481
|
+
it "when joined with 'g?y/./x' " +
|
3482
|
+
"should resolve to http://a/b/c/g?y/./x" do
|
3483
|
+
(@uri + "g?y/./x").to_s.should == "http://a/b/c/g?y/./x"
|
3484
|
+
Addressable::URI.join(
|
3485
|
+
@uri.to_s, "g?y/./x").to_s.should == "http://a/b/c/g?y/./x"
|
3486
|
+
end
|
3487
|
+
|
3488
|
+
# Section 5.4.2 of RFC 3986
|
3489
|
+
it "when joined with 'g?y/../x' " +
|
3490
|
+
"should resolve to http://a/b/c/g?y/../x" do
|
3491
|
+
(@uri + "g?y/../x").to_s.should == "http://a/b/c/g?y/../x"
|
3492
|
+
Addressable::URI.join(
|
3493
|
+
@uri.to_s, "g?y/../x").to_s.should == "http://a/b/c/g?y/../x"
|
3494
|
+
end
|
3495
|
+
|
3496
|
+
# Section 5.4.2 of RFC 3986
|
3497
|
+
it "when joined with 'g#s/./x' " +
|
3498
|
+
"should resolve to http://a/b/c/g#s/./x" do
|
3499
|
+
(@uri + "g#s/./x").to_s.should == "http://a/b/c/g#s/./x"
|
3500
|
+
Addressable::URI.join(
|
3501
|
+
@uri.to_s, "g#s/./x").to_s.should == "http://a/b/c/g#s/./x"
|
3502
|
+
end
|
3503
|
+
|
3504
|
+
# Section 5.4.2 of RFC 3986
|
3505
|
+
it "when joined with 'g#s/../x' " +
|
3506
|
+
"should resolve to http://a/b/c/g#s/../x" do
|
3507
|
+
(@uri + "g#s/../x").to_s.should == "http://a/b/c/g#s/../x"
|
3508
|
+
Addressable::URI.join(
|
3509
|
+
@uri.to_s, "g#s/../x").to_s.should == "http://a/b/c/g#s/../x"
|
3510
|
+
end
|
3511
|
+
|
3512
|
+
# Section 5.4.2 of RFC 3986
|
3513
|
+
it "when joined with 'http:g' should resolve to http:g" do
|
3514
|
+
(@uri + "http:g").to_s.should == "http:g"
|
3515
|
+
Addressable::URI.join(@uri.to_s, "http:g").to_s.should == "http:g"
|
3516
|
+
end
|
3517
|
+
|
3518
|
+
# Edge case to be sure
|
3519
|
+
it "when joined with '//example.com/' should " +
|
3520
|
+
"resolve to http://example.com/" do
|
3521
|
+
(@uri + "//example.com/").to_s.should == "http://example.com/"
|
3522
|
+
Addressable::URI.join(
|
3523
|
+
@uri.to_s, "//example.com/").to_s.should == "http://example.com/"
|
3524
|
+
end
|
3525
|
+
|
3526
|
+
it "when joined with a bogus object a TypeError should be raised" do
|
3527
|
+
(lambda do
|
3528
|
+
Addressable::URI.join(@uri, 42)
|
3529
|
+
end).should raise_error(TypeError)
|
3530
|
+
end
|
3531
|
+
end
|
3532
|
+
|
3533
|
+
describe Addressable::URI, "when converting the path " +
|
3534
|
+
"'relative/path/to/something'" do
|
3535
|
+
before do
|
3536
|
+
@path = 'relative/path/to/something'
|
3537
|
+
end
|
3538
|
+
|
3539
|
+
it "should convert to " +
|
3540
|
+
"\'relative/path/to/something\'" do
|
3541
|
+
@uri = Addressable::URI.convert_path(@path)
|
3542
|
+
@uri.to_str.should == "relative/path/to/something"
|
3543
|
+
end
|
3544
|
+
|
3545
|
+
it "should join with an absolute file path correctly" do
|
3546
|
+
@base = Addressable::URI.convert_path("/absolute/path/")
|
3547
|
+
@uri = Addressable::URI.convert_path(@path)
|
3548
|
+
(@base + @uri).to_str.should ==
|
3549
|
+
"file:///absolute/path/relative/path/to/something"
|
3550
|
+
end
|
3551
|
+
end
|
3552
|
+
|
3553
|
+
describe Addressable::URI, "when converting a bogus path" do
|
3554
|
+
it "should raise a TypeError" do
|
3555
|
+
(lambda do
|
3556
|
+
Addressable::URI.convert_path(42)
|
3557
|
+
end).should raise_error(TypeError)
|
3558
|
+
end
|
3559
|
+
end
|
3560
|
+
|
3561
|
+
describe Addressable::URI, "when given a UNIX root directory" do
|
3562
|
+
before do
|
3563
|
+
@path = "/"
|
3564
|
+
end
|
3565
|
+
|
3566
|
+
it "should convert to \'file:///\'" do
|
3567
|
+
@uri = Addressable::URI.convert_path(@path)
|
3568
|
+
@uri.to_str.should == "file:///"
|
3569
|
+
end
|
3570
|
+
end
|
3571
|
+
|
3572
|
+
describe Addressable::URI, "when given a Windows root directory" do
|
3573
|
+
before do
|
3574
|
+
@path = "C:\\"
|
3575
|
+
end
|
3576
|
+
|
3577
|
+
it "should convert to \'file:///c:/\'" do
|
3578
|
+
@uri = Addressable::URI.convert_path(@path)
|
3579
|
+
@uri.to_str.should == "file:///c:/"
|
3580
|
+
end
|
3581
|
+
end
|
3582
|
+
|
3583
|
+
describe Addressable::URI, "when given the path '/home/user/'" do
|
3584
|
+
before do
|
3585
|
+
@path = '/home/user/'
|
3586
|
+
end
|
3587
|
+
|
3588
|
+
it "should convert to " +
|
3589
|
+
"\'file:///home/user/\'" do
|
3590
|
+
@uri = Addressable::URI.convert_path(@path)
|
3591
|
+
@uri.to_str.should == "file:///home/user/"
|
3592
|
+
end
|
3593
|
+
end
|
3594
|
+
|
3595
|
+
describe Addressable::URI, "when given the path " +
|
3596
|
+
"'c:\\windows\\My Documents 100%20\\foo.txt'" do
|
3597
|
+
before do
|
3598
|
+
@path = "c:\\windows\\My Documents 100%20\\foo.txt"
|
3599
|
+
end
|
3600
|
+
|
3601
|
+
it "should convert to " +
|
3602
|
+
"\'file:///c:/windows/My%20Documents%20100%20/foo.txt\'" do
|
3603
|
+
@uri = Addressable::URI.convert_path(@path)
|
3604
|
+
@uri.to_str.should == "file:///c:/windows/My%20Documents%20100%20/foo.txt"
|
3605
|
+
end
|
3606
|
+
end
|
3607
|
+
|
3608
|
+
describe Addressable::URI, "when given the path " +
|
3609
|
+
"'file://c:\\windows\\My Documents 100%20\\foo.txt'" do
|
3610
|
+
before do
|
3611
|
+
@path = "file://c:\\windows\\My Documents 100%20\\foo.txt"
|
3612
|
+
end
|
3613
|
+
|
3614
|
+
it "should convert to " +
|
3615
|
+
"\'file:///c:/windows/My%20Documents%20100%20/foo.txt\'" do
|
3616
|
+
@uri = Addressable::URI.convert_path(@path)
|
3617
|
+
@uri.to_str.should == "file:///c:/windows/My%20Documents%20100%20/foo.txt"
|
3618
|
+
end
|
3619
|
+
end
|
3620
|
+
|
3621
|
+
describe Addressable::URI, "when given the path " +
|
3622
|
+
"'file:c:\\windows\\My Documents 100%20\\foo.txt'" do
|
3623
|
+
before do
|
3624
|
+
@path = "file:c:\\windows\\My Documents 100%20\\foo.txt"
|
3625
|
+
end
|
3626
|
+
|
3627
|
+
it "should convert to " +
|
3628
|
+
"\'file:///c:/windows/My%20Documents%20100%20/foo.txt\'" do
|
3629
|
+
@uri = Addressable::URI.convert_path(@path)
|
3630
|
+
@uri.to_str.should == "file:///c:/windows/My%20Documents%20100%20/foo.txt"
|
3631
|
+
end
|
3632
|
+
end
|
3633
|
+
|
3634
|
+
describe Addressable::URI, "when given the path " +
|
3635
|
+
"'file:/c:\\windows\\My Documents 100%20\\foo.txt'" do
|
3636
|
+
before do
|
3637
|
+
@path = "file:/c:\\windows\\My Documents 100%20\\foo.txt"
|
3638
|
+
end
|
3639
|
+
|
3640
|
+
it "should convert to " +
|
3641
|
+
"\'file:///c:/windows/My%20Documents%20100%20/foo.txt\'" do
|
3642
|
+
@uri = Addressable::URI.convert_path(@path)
|
3643
|
+
@uri.to_str.should == "file:///c:/windows/My%20Documents%20100%20/foo.txt"
|
3644
|
+
end
|
3645
|
+
end
|
3646
|
+
|
3647
|
+
describe Addressable::URI, "when given the path " +
|
3648
|
+
"'file:///c|/windows/My%20Documents%20100%20/foo.txt'" do
|
3649
|
+
before do
|
3650
|
+
@path = "file:///c|/windows/My%20Documents%20100%20/foo.txt"
|
3651
|
+
end
|
3652
|
+
|
3653
|
+
it "should convert to " +
|
3654
|
+
"\'file:///c:/windows/My%20Documents%20100%20/foo.txt\'" do
|
3655
|
+
@uri = Addressable::URI.convert_path(@path)
|
3656
|
+
@uri.to_str.should == "file:///c:/windows/My%20Documents%20100%20/foo.txt"
|
3657
|
+
end
|
3658
|
+
end
|
3659
|
+
|
3660
|
+
describe Addressable::URI, "when given an http protocol URI" do
|
3661
|
+
before do
|
3662
|
+
@path = "http://example.com/"
|
3663
|
+
end
|
3664
|
+
|
3665
|
+
it "should not do any conversion at all" do
|
3666
|
+
@uri = Addressable::URI.convert_path(@path)
|
3667
|
+
@uri.to_str.should == "http://example.com/"
|
3668
|
+
end
|
3669
|
+
end
|
3670
|
+
|
3671
|
+
class SuperString
|
3672
|
+
def initialize(string)
|
3673
|
+
@string = string.to_s
|
3674
|
+
end
|
3675
|
+
|
3676
|
+
def to_str
|
3677
|
+
return @string
|
3678
|
+
end
|
3679
|
+
end
|
3680
|
+
|
3681
|
+
describe Addressable::URI, "when parsing a non-String object" do
|
3682
|
+
it "should correctly parse anything with a 'to_str' method" do
|
3683
|
+
Addressable::URI.parse(SuperString.new(42))
|
3684
|
+
end
|
3685
|
+
|
3686
|
+
it "should raise a TypeError for objects than cannot be converted" do
|
3687
|
+
(lambda do
|
3688
|
+
Addressable::URI.parse(42)
|
3689
|
+
end).should raise_error(TypeError, "Can't convert Fixnum into String.")
|
3690
|
+
end
|
3691
|
+
|
3692
|
+
it "should correctly parse heuristically anything with a 'to_str' method" do
|
3693
|
+
Addressable::URI.heuristic_parse(SuperString.new(42))
|
3694
|
+
end
|
3695
|
+
|
3696
|
+
it "should raise a TypeError for objects than cannot be converted" do
|
3697
|
+
(lambda do
|
3698
|
+
Addressable::URI.heuristic_parse(42)
|
3699
|
+
end).should raise_error(TypeError, "Can't convert Fixnum into String.")
|
3700
|
+
end
|
3701
|
+
end
|
3702
|
+
|
3703
|
+
describe Addressable::URI, "when form encoding a hash" do
|
3704
|
+
it "should result in correct percent encoded sequence" do
|
3705
|
+
Addressable::URI.form_encode(
|
3706
|
+
{"&one" => "/1", "=two" => "?2", ":three" => "#3"}
|
3707
|
+
).should == "%26one=%2F1&%3Dtwo=%3F2&%3Athree=%233"
|
3708
|
+
end
|
3709
|
+
|
3710
|
+
it "should result in correct percent encoded sequence" do
|
3711
|
+
Addressable::URI.form_encode(
|
3712
|
+
{"q" => "one two three"}
|
3713
|
+
).should == "q=one+two+three"
|
3714
|
+
end
|
3715
|
+
|
3716
|
+
it "should result in correct percent encoded sequence" do
|
3717
|
+
Addressable::URI.form_encode(
|
3718
|
+
{"key" => nil}
|
3719
|
+
).should == "key="
|
3720
|
+
end
|
3721
|
+
|
3722
|
+
it "should result in correctly encoded newlines" do
|
3723
|
+
Addressable::URI.form_encode(
|
3724
|
+
{"text" => "one\ntwo\rthree\r\nfour\n\r"}
|
3725
|
+
).should == "text=one%0D%0Atwo%0D%0Athree%0D%0Afour%0D%0A%0D%0A"
|
3726
|
+
end
|
3727
|
+
|
3728
|
+
it "should result in a sorted percent encoded sequence" do
|
3729
|
+
Addressable::URI.form_encode(
|
3730
|
+
[["a", "1"], ["dup", "3"], ["dup", "2"]], true
|
3731
|
+
).should == "a=1&dup=2&dup=3"
|
3732
|
+
end
|
3733
|
+
end
|
3734
|
+
|
3735
|
+
describe Addressable::URI, "when form encoding a non-Array object" do
|
3736
|
+
it "should raise a TypeError for objects than cannot be converted" do
|
3737
|
+
(lambda do
|
3738
|
+
Addressable::URI.form_encode(42)
|
3739
|
+
end).should raise_error(TypeError, "Can't convert Fixnum into Array.")
|
3740
|
+
end
|
3741
|
+
end
|
3742
|
+
|
3743
|
+
describe Addressable::URI, "when form unencoding a string" do
|
3744
|
+
it "should result in correct values" do
|
3745
|
+
Addressable::URI.form_unencode(
|
3746
|
+
"%26one=%2F1&%3Dtwo=%3F2&%3Athree=%233"
|
3747
|
+
).should == [["&one", "/1"], ["=two", "?2"], [":three", "#3"]]
|
3748
|
+
end
|
3749
|
+
|
3750
|
+
it "should result in correct values" do
|
3751
|
+
Addressable::URI.form_unencode(
|
3752
|
+
"q=one+two+three"
|
3753
|
+
).should == [["q", "one two three"]]
|
3754
|
+
end
|
3755
|
+
|
3756
|
+
it "should result in correct values" do
|
3757
|
+
Addressable::URI.form_unencode(
|
3758
|
+
"text=one%0D%0Atwo%0D%0Athree%0D%0Afour%0D%0A%0D%0A"
|
3759
|
+
).should == [["text", "one\ntwo\nthree\nfour\n\n"]]
|
3760
|
+
end
|
3761
|
+
|
3762
|
+
it "should result in correct values" do
|
3763
|
+
Addressable::URI.form_unencode(
|
3764
|
+
"a=1&dup=2&dup=3"
|
3765
|
+
).should == [["a", "1"], ["dup", "2"], ["dup", "3"]]
|
3766
|
+
end
|
3767
|
+
|
3768
|
+
it "should result in correct values" do
|
3769
|
+
Addressable::URI.form_unencode(
|
3770
|
+
"key"
|
3771
|
+
).should == [["key", nil]]
|
3772
|
+
end
|
3773
|
+
|
3774
|
+
it "should result in correct values" do
|
3775
|
+
Addressable::URI.form_unencode("GivenName=Ren%C3%A9").should ==
|
3776
|
+
[["GivenName", "René"]]
|
3777
|
+
end
|
3778
|
+
end
|
3779
|
+
|
3780
|
+
describe Addressable::URI, "when form unencoding a non-String object" do
|
3781
|
+
it "should correctly parse anything with a 'to_str' method" do
|
3782
|
+
Addressable::URI.form_unencode(SuperString.new(42))
|
3783
|
+
end
|
3784
|
+
|
3785
|
+
it "should raise a TypeError for objects than cannot be converted" do
|
3786
|
+
(lambda do
|
3787
|
+
Addressable::URI.form_unencode(42)
|
3788
|
+
end).should raise_error(TypeError, "Can't convert Fixnum into String.")
|
3789
|
+
end
|
3790
|
+
end
|
3791
|
+
|
3792
|
+
describe Addressable::URI, "when normalizing a non-String object" do
|
3793
|
+
it "should correctly parse anything with a 'to_str' method" do
|
3794
|
+
Addressable::URI.normalize_component(SuperString.new(42))
|
3795
|
+
end
|
3796
|
+
|
3797
|
+
it "should raise a TypeError for objects than cannot be converted" do
|
3798
|
+
(lambda do
|
3799
|
+
Addressable::URI.normalize_component(42)
|
3800
|
+
end).should raise_error(TypeError, "Can't convert Fixnum into String.")
|
3801
|
+
end
|
3802
|
+
|
3803
|
+
it "should raise a TypeError for objects than cannot be converted" do
|
3804
|
+
(lambda do
|
3805
|
+
Addressable::URI.normalize_component("component", 42)
|
3806
|
+
end).should raise_error(TypeError)
|
3807
|
+
end
|
3808
|
+
end
|
3809
|
+
|
3810
|
+
describe Addressable::URI, "when normalizing a path with an encoded slash" do
|
3811
|
+
it "should result in correct percent encoded sequence" do
|
3812
|
+
Addressable::URI.parse("/path%2Fsegment/").normalize.path.should ==
|
3813
|
+
"/path%2Fsegment/"
|
3814
|
+
end
|
3815
|
+
end
|
3816
|
+
|
3817
|
+
describe Addressable::URI, "when normalizing a partially encoded string" do
|
3818
|
+
it "should result in correct percent encoded sequence" do
|
3819
|
+
Addressable::URI.normalize_component(
|
3820
|
+
"partially % encoded%21"
|
3821
|
+
).should == "partially%20%25%20encoded!"
|
3822
|
+
end
|
3823
|
+
|
3824
|
+
it "should result in correct percent encoded sequence" do
|
3825
|
+
Addressable::URI.normalize_component(
|
3826
|
+
"partially %25 encoded!"
|
3827
|
+
).should == "partially%20%25%20encoded!"
|
3828
|
+
end
|
3829
|
+
end
|
3830
|
+
|
3831
|
+
describe Addressable::URI, "when normalizing a unicode sequence" do
|
3832
|
+
it "should result in correct percent encoded sequence" do
|
3833
|
+
Addressable::URI.normalize_component(
|
3834
|
+
"/C%CC%A7"
|
3835
|
+
).should == "/%C3%87"
|
3836
|
+
end
|
3837
|
+
|
3838
|
+
it "should result in correct percent encoded sequence" do
|
3839
|
+
Addressable::URI.normalize_component(
|
3840
|
+
"/%C3%87"
|
3841
|
+
).should == "/%C3%87"
|
3842
|
+
end
|
3843
|
+
end
|
3844
|
+
|
3845
|
+
describe Addressable::URI, "when normalizing a multibyte string" do
|
3846
|
+
it "should result in correct percent encoded sequence" do
|
3847
|
+
Addressable::URI.normalize_component("günther").should ==
|
3848
|
+
"g%C3%BCnther"
|
3849
|
+
end
|
3850
|
+
|
3851
|
+
it "should result in correct percent encoded sequence" do
|
3852
|
+
Addressable::URI.normalize_component("g%C3%BCnther").should ==
|
3853
|
+
"g%C3%BCnther"
|
3854
|
+
end
|
3855
|
+
end
|
3856
|
+
|
3857
|
+
describe Addressable::URI, "when encoding a multibyte string" do
|
3858
|
+
it "should result in correct percent encoded sequence" do
|
3859
|
+
Addressable::URI.encode_component("günther").should == "g%C3%BCnther"
|
3860
|
+
end
|
3861
|
+
|
3862
|
+
it "should result in correct percent encoded sequence" do
|
3863
|
+
Addressable::URI.encode_component(
|
3864
|
+
"günther", /[^a-zA-Z0-9\:\/\?\#\[\]\@\!\$\&\'\(\)\*\+\,\;\=\-\.\_\~]/
|
3865
|
+
).should == "g%C3%BCnther"
|
3866
|
+
end
|
3867
|
+
end
|
3868
|
+
|
3869
|
+
describe Addressable::URI, "when form encoding a multibyte string" do
|
3870
|
+
it "should result in correct percent encoded sequence" do
|
3871
|
+
Addressable::URI.form_encode({"GivenName" => "René"}).should ==
|
3872
|
+
"GivenName=Ren%C3%A9"
|
3873
|
+
end
|
3874
|
+
end
|
3875
|
+
|
3876
|
+
describe Addressable::URI, "when encoding a string with ASCII chars 0-15" do
|
3877
|
+
it "should result in correct percent encoded sequence" do
|
3878
|
+
Addressable::URI.encode_component("one\ntwo").should == "one%0Atwo"
|
3879
|
+
end
|
3880
|
+
|
3881
|
+
it "should result in correct percent encoded sequence" do
|
3882
|
+
Addressable::URI.encode_component(
|
3883
|
+
"one\ntwo", /[^a-zA-Z0-9\:\/\?\#\[\]\@\!\$\&\'\(\)\*\+\,\;\=\-\.\_\~]/
|
3884
|
+
).should == "one%0Atwo"
|
3885
|
+
end
|
3886
|
+
end
|
3887
|
+
|
3888
|
+
describe Addressable::URI, "when unencoding a multibyte string" do
|
3889
|
+
it "should result in correct percent encoded sequence" do
|
3890
|
+
Addressable::URI.unencode_component("g%C3%BCnther").should == "günther"
|
3891
|
+
end
|
3892
|
+
|
3893
|
+
it "should result in correct percent encoded sequence as a URI" do
|
3894
|
+
Addressable::URI.unencode(
|
3895
|
+
"/path?g%C3%BCnther", ::Addressable::URI
|
3896
|
+
).should == Addressable::URI.new(
|
3897
|
+
:path => "/path", :query => "günther"
|
3898
|
+
)
|
3899
|
+
end
|
3900
|
+
end
|
3901
|
+
|
3902
|
+
describe Addressable::URI, "when unencoding a bogus object" do
|
3903
|
+
it "should raise a TypeError" do
|
3904
|
+
(lambda do
|
3905
|
+
Addressable::URI.unencode_component(42)
|
3906
|
+
end).should raise_error(TypeError)
|
3907
|
+
end
|
3908
|
+
|
3909
|
+
it "should raise a TypeError" do
|
3910
|
+
(lambda do
|
3911
|
+
Addressable::URI.unencode("/path?g%C3%BCnther", Integer)
|
3912
|
+
end).should raise_error(TypeError)
|
3913
|
+
end
|
3914
|
+
end
|
3915
|
+
|
3916
|
+
describe Addressable::URI, "when encoding a bogus object" do
|
3917
|
+
it "should raise a TypeError" do
|
3918
|
+
(lambda do
|
3919
|
+
Addressable::URI.encode(42)
|
3920
|
+
end).should raise_error(TypeError)
|
3921
|
+
end
|
3922
|
+
|
3923
|
+
it "should raise a TypeError" do
|
3924
|
+
(lambda do
|
3925
|
+
Addressable::URI.normalized_encode(42)
|
3926
|
+
end).should raise_error(TypeError)
|
3927
|
+
end
|
3928
|
+
|
3929
|
+
it "should raise a TypeError" do
|
3930
|
+
(lambda do
|
3931
|
+
Addressable::URI.encode_component("günther", 42)
|
3932
|
+
end).should raise_error(TypeError)
|
3933
|
+
end
|
3934
|
+
|
3935
|
+
it "should raise a TypeError" do
|
3936
|
+
(lambda do
|
3937
|
+
Addressable::URI.encode_component(42)
|
3938
|
+
end).should raise_error(TypeError)
|
3939
|
+
end
|
3940
|
+
end
|
3941
|
+
|
3942
|
+
describe Addressable::URI, "when given the input " +
|
3943
|
+
"'http://example.com/'" do
|
3944
|
+
before do
|
3945
|
+
@input = "http://example.com/"
|
3946
|
+
end
|
3947
|
+
|
3948
|
+
it "should heuristically parse to 'http://example.com/'" do
|
3949
|
+
@uri = Addressable::URI.heuristic_parse(@input)
|
3950
|
+
@uri.to_s.should == "http://example.com/"
|
3951
|
+
end
|
3952
|
+
end
|
3953
|
+
|
3954
|
+
|
3955
|
+
describe Addressable::URI, "when given the input " +
|
3956
|
+
"'http:example.com/'" do
|
3957
|
+
before do
|
3958
|
+
@input = "http:example.com/"
|
3959
|
+
end
|
3960
|
+
|
3961
|
+
it "should heuristically parse to 'http://example.com/'" do
|
3962
|
+
@uri = Addressable::URI.heuristic_parse(@input)
|
3963
|
+
@uri.to_s.should == "http://example.com/"
|
3964
|
+
end
|
3965
|
+
|
3966
|
+
it "should heuristically parse to 'http://example.com/' " +
|
3967
|
+
"even with a scheme hint of 'ftp'" do
|
3968
|
+
@uri = Addressable::URI.heuristic_parse(@input, {:scheme => 'ftp'})
|
3969
|
+
@uri.to_s.should == "http://example.com/"
|
3970
|
+
end
|
3971
|
+
end
|
3972
|
+
|
3973
|
+
describe Addressable::URI, "when given the input " +
|
3974
|
+
"'http://example.com/example.com/'" do
|
3975
|
+
before do
|
3976
|
+
@input = "http://example.com/example.com/"
|
3977
|
+
end
|
3978
|
+
|
3979
|
+
it "should heuristically parse to 'http://example.com/example.com/'" do
|
3980
|
+
@uri = Addressable::URI.heuristic_parse(@input)
|
3981
|
+
@uri.to_s.should == "http://example.com/example.com/"
|
3982
|
+
end
|
3983
|
+
end
|
3984
|
+
|
3985
|
+
describe Addressable::URI, "when given the input " +
|
3986
|
+
"'/path/to/resource'" do
|
3987
|
+
before do
|
3988
|
+
@input = "/path/to/resource"
|
3989
|
+
end
|
3990
|
+
|
3991
|
+
it "should heuristically parse to '/path/to/resource'" do
|
3992
|
+
@uri = Addressable::URI.heuristic_parse(@input)
|
3993
|
+
@uri.to_s.should == "/path/to/resource"
|
3994
|
+
end
|
3995
|
+
end
|
3996
|
+
|
3997
|
+
describe Addressable::URI, "when given the input " +
|
3998
|
+
"'relative/path/to/resource'" do
|
3999
|
+
before do
|
4000
|
+
@input = "relative/path/to/resource"
|
4001
|
+
end
|
4002
|
+
|
4003
|
+
it "should heuristically parse to 'relative/path/to/resource'" do
|
4004
|
+
@uri = Addressable::URI.heuristic_parse(@input)
|
4005
|
+
@uri.to_s.should == "relative/path/to/resource"
|
4006
|
+
end
|
4007
|
+
end
|
4008
|
+
|
4009
|
+
describe Addressable::URI, "when given the input " +
|
4010
|
+
"'example.com'" do
|
4011
|
+
before do
|
4012
|
+
@input = "example.com"
|
4013
|
+
end
|
4014
|
+
|
4015
|
+
it "should heuristically parse to 'http://example.com'" do
|
4016
|
+
@uri = Addressable::URI.heuristic_parse(@input)
|
4017
|
+
@uri.to_s.should == "http://example.com"
|
4018
|
+
end
|
4019
|
+
end
|
4020
|
+
|
4021
|
+
describe Addressable::URI, "when given the input " +
|
4022
|
+
"'example.com' and a scheme hint of 'ftp'" do
|
4023
|
+
before do
|
4024
|
+
@input = "example.com"
|
4025
|
+
@hints = {:scheme => 'ftp'}
|
4026
|
+
end
|
4027
|
+
|
4028
|
+
it "should heuristically parse to 'http://example.com'" do
|
4029
|
+
@uri = Addressable::URI.heuristic_parse(@input, @hints)
|
4030
|
+
@uri.to_s.should == "ftp://example.com"
|
4031
|
+
end
|
4032
|
+
end
|
4033
|
+
|
4034
|
+
describe Addressable::URI, "when given the input " +
|
4035
|
+
"'example.com:21' and a scheme hint of 'ftp'" do
|
4036
|
+
before do
|
4037
|
+
@input = "example.com:21"
|
4038
|
+
@hints = {:scheme => 'ftp'}
|
4039
|
+
end
|
4040
|
+
|
4041
|
+
it "should heuristically parse to 'http://example.com:21'" do
|
4042
|
+
@uri = Addressable::URI.heuristic_parse(@input, @hints)
|
4043
|
+
@uri.to_s.should == "ftp://example.com:21"
|
4044
|
+
end
|
4045
|
+
end
|
4046
|
+
|
4047
|
+
describe Addressable::URI, "when given the input " +
|
4048
|
+
"'example.com/path/to/resource'" do
|
4049
|
+
before do
|
4050
|
+
@input = "example.com/path/to/resource"
|
4051
|
+
end
|
4052
|
+
|
4053
|
+
it "should heuristically parse to 'http://example.com/path/to/resource'" do
|
4054
|
+
@uri = Addressable::URI.heuristic_parse(@input)
|
4055
|
+
@uri.to_s.should == "http://example.com/path/to/resource"
|
4056
|
+
end
|
4057
|
+
end
|
4058
|
+
|
4059
|
+
describe Addressable::URI, "when given the input " +
|
4060
|
+
"'http:///example.com'" do
|
4061
|
+
before do
|
4062
|
+
@input = "http:///example.com"
|
4063
|
+
end
|
4064
|
+
|
4065
|
+
it "should heuristically parse to 'http://example.com'" do
|
4066
|
+
@uri = Addressable::URI.heuristic_parse(@input)
|
4067
|
+
@uri.to_s.should == "http://example.com"
|
4068
|
+
end
|
4069
|
+
end
|
4070
|
+
|
4071
|
+
describe Addressable::URI, "when given the input " +
|
4072
|
+
"'feed:///example.com'" do
|
4073
|
+
before do
|
4074
|
+
@input = "feed:///example.com"
|
4075
|
+
end
|
4076
|
+
|
4077
|
+
it "should heuristically parse to 'feed://example.com'" do
|
4078
|
+
@uri = Addressable::URI.heuristic_parse(@input)
|
4079
|
+
@uri.to_s.should == "feed://example.com"
|
4080
|
+
end
|
4081
|
+
end
|
4082
|
+
|
4083
|
+
describe Addressable::URI, "when given the input " +
|
4084
|
+
"'file://path/to/resource/'" do
|
4085
|
+
before do
|
4086
|
+
@input = "file://path/to/resource/"
|
4087
|
+
end
|
4088
|
+
|
4089
|
+
it "should heuristically parse to 'file:///path/to/resource/'" do
|
4090
|
+
@uri = Addressable::URI.heuristic_parse(@input)
|
4091
|
+
@uri.to_s.should == "file:///path/to/resource/"
|
4092
|
+
end
|
4093
|
+
end
|
4094
|
+
|
4095
|
+
describe Addressable::URI, "when given the input " +
|
4096
|
+
"'feed://http://example.com'" do
|
4097
|
+
before do
|
4098
|
+
@input = "feed://http://example.com"
|
4099
|
+
end
|
4100
|
+
|
4101
|
+
it "should heuristically parse to 'feed:http://example.com'" do
|
4102
|
+
@uri = Addressable::URI.heuristic_parse(@input)
|
4103
|
+
@uri.to_s.should == "feed:http://example.com"
|
4104
|
+
end
|
4105
|
+
end
|
4106
|
+
|
4107
|
+
describe Addressable::URI, "when assigning query values" do
|
4108
|
+
before do
|
4109
|
+
@uri = Addressable::URI.new
|
4110
|
+
end
|
4111
|
+
|
4112
|
+
it "should correctly assign {:a => 'a', :b => ['c', 'd', 'e']}" do
|
4113
|
+
@uri.query_values = {:a => "a", :b => ["c", "d", "e"]}
|
4114
|
+
@uri.query.should == "a=a&b[0]=c&b[1]=d&b[2]=e"
|
4115
|
+
end
|
4116
|
+
|
4117
|
+
it "should correctly assign " +
|
4118
|
+
"{:a => 'a', :b => [{:c => 'c', :d => 'd'}, {:e => 'e', :f => 'f'}]}" do
|
4119
|
+
@uri.query_values = {
|
4120
|
+
:a => "a", :b => [{:c => "c", :d => "d"}, {:e => "e", :f => "f"}]
|
4121
|
+
}
|
4122
|
+
@uri.query.should == "a=a&b[0][c]=c&b[0][d]=d&b[1][e]=e&b[1][f]=f"
|
4123
|
+
end
|
4124
|
+
|
4125
|
+
it "should correctly assign " +
|
4126
|
+
"{:a => 'a', :b => [{:c => true, :d => 'd'}, {:e => 'e', :f => 'f'}]}" do
|
4127
|
+
@uri.query_values = {
|
4128
|
+
:a => 'a', :b => [{:c => true, :d => 'd'}, {:e => 'e', :f => 'f'}]
|
4129
|
+
}
|
4130
|
+
@uri.query.should == "a=a&b[0][c]&b[0][d]=d&b[1][e]=e&b[1][f]=f"
|
4131
|
+
end
|
4132
|
+
|
4133
|
+
it "should correctly assign " +
|
4134
|
+
"{:a => 'a', :b => {:c => true, :d => 'd'}}" do
|
4135
|
+
@uri.query_values = {
|
4136
|
+
:a => 'a', :b => {:c => true, :d => 'd'}
|
4137
|
+
}
|
4138
|
+
@uri.query.should == "a=a&b[c]&b[d]=d"
|
4139
|
+
end
|
4140
|
+
|
4141
|
+
it "should correctly assign " +
|
4142
|
+
"{:a => 'a', :b => {:c => true, :d => 'd'}, :e => []}" do
|
4143
|
+
@uri.query_values = {
|
4144
|
+
:a => 'a', :b => {:c => true, :d => 'd'}
|
4145
|
+
}
|
4146
|
+
@uri.query.should == "a=a&b[c]&b[d]=d"
|
4147
|
+
end
|
4148
|
+
|
4149
|
+
it "should correctly assign {}" do
|
4150
|
+
@uri.query_values = {}
|
4151
|
+
@uri.query.should == ''
|
4152
|
+
end
|
4153
|
+
|
4154
|
+
it "should correctly assign nil" do
|
4155
|
+
@uri.query_values = nil
|
4156
|
+
@uri.query.should == nil
|
4157
|
+
end
|
4158
|
+
|
4159
|
+
it "should correctly sort {'ab' => 'c', :ab => 'a', :a => 'x'}" do
|
4160
|
+
@uri.query_values = {'ab' => 'c', :ab => 'a', :a => 'x'}
|
4161
|
+
@uri.query.should == "a=x&ab=a&ab=c"
|
4162
|
+
end
|
4163
|
+
end
|
4164
|
+
|
4165
|
+
describe Addressable::URI, "when assigning path values" do
|
4166
|
+
before do
|
4167
|
+
@uri = Addressable::URI.new
|
4168
|
+
end
|
4169
|
+
|
4170
|
+
it "should correctly assign paths containing colons" do
|
4171
|
+
@uri.path = "acct:bob@sporkmonger.com"
|
4172
|
+
Addressable::URI.parse(@uri.normalize.to_str).path.should == @uri.path
|
4173
|
+
@uri.normalize.to_str.should == "acct%2Fbob@sporkmonger.com"
|
4174
|
+
end
|
4175
|
+
|
4176
|
+
it "should correctly assign paths containing colons" do
|
4177
|
+
@uri.path = "/acct:bob@sporkmonger.com"
|
4178
|
+
@uri.authority = "example.com"
|
4179
|
+
@uri.normalize.to_str.should == "//example.com/acct:bob@sporkmonger.com"
|
4180
|
+
end
|
4181
|
+
|
4182
|
+
it "should correctly assign paths containing colons" do
|
4183
|
+
@uri.path = "acct:bob@sporkmonger.com"
|
4184
|
+
@uri.scheme = "something"
|
4185
|
+
@uri.normalize.to_str.should == "something:acct:bob@sporkmonger.com"
|
4186
|
+
end
|
4187
|
+
|
4188
|
+
it "should not allow relative paths to be assigned on absolute URIs" do
|
4189
|
+
(lambda do
|
4190
|
+
@uri.scheme = "http"
|
4191
|
+
@uri.host = "example.com"
|
4192
|
+
@uri.path = "acct:bob@sporkmonger.com"
|
4193
|
+
end).should raise_error(Addressable::URI::InvalidURIError)
|
4194
|
+
end
|
4195
|
+
|
4196
|
+
it "should not allow relative paths to be assigned on absolute URIs" do
|
4197
|
+
(lambda do
|
4198
|
+
@uri.path = "acct:bob@sporkmonger.com"
|
4199
|
+
@uri.scheme = "http"
|
4200
|
+
@uri.host = "example.com"
|
4201
|
+
end).should raise_error(Addressable::URI::InvalidURIError)
|
4202
|
+
end
|
4203
|
+
|
4204
|
+
it "should not allow relative paths to be assigned on absolute URIs" do
|
4205
|
+
(lambda do
|
4206
|
+
@uri.path = "uuid:0b3ecf60-3f93-11df-a9c3-001f5bfffe12"
|
4207
|
+
@uri.scheme = "urn"
|
4208
|
+
end).should_not raise_error(Addressable::URI::InvalidURIError)
|
4209
|
+
end
|
4210
|
+
end
|