addressabler 0.0.7 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
- # Copyright (C) 2006-2011 Bob Aman
2
+ # Copyright (C) 2006-2013 Bob Aman
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
@@ -14,6 +14,8 @@
14
14
  # limitations under the License.
15
15
 
16
16
 
17
+ require "spec_helper"
18
+
17
19
  require "addressable/uri"
18
20
 
19
21
  if !"".respond_to?("force_encoding")
@@ -41,14 +43,18 @@ if !"".respond_to?("force_encoding")
41
43
  end
42
44
  end
43
45
 
44
- module URI
45
- class HTTP
46
- def initialize(uri)
47
- @uri = uri
48
- end
46
+ module Fake
47
+ module URI
48
+ class HTTP
49
+ def initialize(uri)
50
+ @uri = uri
51
+ end
49
52
 
50
- def to_s
51
- return @uri.to_s
53
+ def to_s
54
+ return @uri.to_s
55
+ end
56
+
57
+ alias :to_str :to_s
52
58
  end
53
59
  end
54
60
  end
@@ -179,6 +185,10 @@ describe Addressable::URI, "when created from nil components" do
179
185
  @uri.default_port.should == nil
180
186
  end
181
187
 
188
+ it "should be empty" do
189
+ @uri.should be_empty
190
+ end
191
+
182
192
  it "should raise an error if the scheme is set to whitespace" do
183
193
  (lambda do
184
194
  @uri.scheme = "\t \n"
@@ -218,6 +228,384 @@ describe Addressable::URI, "when created from nil components" do
218
228
  end
219
229
  end
220
230
 
231
+ describe Addressable::URI, "when initialized from individual components" do
232
+ before do
233
+ @uri = Addressable::URI.new(
234
+ :scheme => "http",
235
+ :user => "user",
236
+ :password => "password",
237
+ :host => "example.com",
238
+ :port => 8080,
239
+ :path => "/path",
240
+ :query => "query=value",
241
+ :fragment => "fragment"
242
+ )
243
+ end
244
+
245
+ it "returns 'http' for #scheme" do
246
+ @uri.scheme.should == "http"
247
+ end
248
+
249
+ it "returns 'http' for #normalized_scheme" do
250
+ @uri.normalized_scheme.should == "http"
251
+ end
252
+
253
+ it "returns 'user' for #user" do
254
+ @uri.user.should == "user"
255
+ end
256
+
257
+ it "returns 'user' for #normalized_user" do
258
+ @uri.normalized_user.should == "user"
259
+ end
260
+
261
+ it "returns 'password' for #password" do
262
+ @uri.password.should == "password"
263
+ end
264
+
265
+ it "returns 'password' for #normalized_password" do
266
+ @uri.normalized_password.should == "password"
267
+ end
268
+
269
+ it "returns 'user:password' for #userinfo" do
270
+ @uri.userinfo.should == "user:password"
271
+ end
272
+
273
+ it "returns 'user:password' for #normalized_userinfo" do
274
+ @uri.normalized_userinfo.should == "user:password"
275
+ end
276
+
277
+ it "returns 'example.com' for #host" do
278
+ @uri.host.should == "example.com"
279
+ end
280
+
281
+ it "returns 'example.com' for #normalized_host" do
282
+ @uri.normalized_host.should == "example.com"
283
+ end
284
+
285
+ it "returns 'user:password@example.com:8080' for #authority" do
286
+ @uri.authority.should == "user:password@example.com:8080"
287
+ end
288
+
289
+ it "returns 'user:password@example.com:8080' for #normalized_authority" do
290
+ @uri.normalized_authority.should == "user:password@example.com:8080"
291
+ end
292
+
293
+ it "returns 8080 for #port" do
294
+ @uri.port.should == 8080
295
+ end
296
+
297
+ it "returns 8080 for #normalized_port" do
298
+ @uri.normalized_port.should == 8080
299
+ end
300
+
301
+ it "returns 80 for #default_port" do
302
+ @uri.default_port.should == 80
303
+ end
304
+
305
+ it "returns 'http://user:password@example.com:8080' for #site" do
306
+ @uri.site.should == "http://user:password@example.com:8080"
307
+ end
308
+
309
+ it "returns 'http://user:password@example.com:8080' for #normalized_site" do
310
+ @uri.normalized_site.should == "http://user:password@example.com:8080"
311
+ end
312
+
313
+ it "returns '/path' for #path" do
314
+ @uri.path.should == "/path"
315
+ end
316
+
317
+ it "returns '/path' for #normalized_path" do
318
+ @uri.normalized_path.should == "/path"
319
+ end
320
+
321
+ it "returns 'query=value' for #query" do
322
+ @uri.query.should == "query=value"
323
+ end
324
+
325
+ it "returns 'query=value' for #normalized_query" do
326
+ @uri.normalized_query.should == "query=value"
327
+ end
328
+
329
+ it "returns 'fragment' for #fragment" do
330
+ @uri.fragment.should == "fragment"
331
+ end
332
+
333
+ it "returns 'fragment' for #normalized_fragment" do
334
+ @uri.normalized_fragment.should == "fragment"
335
+ end
336
+
337
+ it "returns #hash" do
338
+ @uri.hash.should_not be nil
339
+ end
340
+
341
+ it "returns #to_s" do
342
+ @uri.to_s.should ==
343
+ "http://user:password@example.com:8080/path?query=value#fragment"
344
+ end
345
+
346
+ it "should not be empty" do
347
+ @uri.should_not be_empty
348
+ end
349
+
350
+ it "should not be frozen" do
351
+ @uri.should_not be_frozen
352
+ end
353
+
354
+ it "should allow destructive operations" do
355
+ expect { @uri.normalize! }.not_to raise_error
356
+ end
357
+ end
358
+
359
+ describe Addressable::URI, "when initialized from " +
360
+ "frozen individual components" do
361
+ before do
362
+ @uri = Addressable::URI.new(
363
+ :scheme => "http".freeze,
364
+ :user => "user".freeze,
365
+ :password => "password".freeze,
366
+ :host => "example.com".freeze,
367
+ :port => "8080".freeze,
368
+ :path => "/path".freeze,
369
+ :query => "query=value".freeze,
370
+ :fragment => "fragment".freeze
371
+ )
372
+ end
373
+
374
+ it "returns 'http' for #scheme" do
375
+ @uri.scheme.should == "http"
376
+ end
377
+
378
+ it "returns 'http' for #normalized_scheme" do
379
+ @uri.normalized_scheme.should == "http"
380
+ end
381
+
382
+ it "returns 'user' for #user" do
383
+ @uri.user.should == "user"
384
+ end
385
+
386
+ it "returns 'user' for #normalized_user" do
387
+ @uri.normalized_user.should == "user"
388
+ end
389
+
390
+ it "returns 'password' for #password" do
391
+ @uri.password.should == "password"
392
+ end
393
+
394
+ it "returns 'password' for #normalized_password" do
395
+ @uri.normalized_password.should == "password"
396
+ end
397
+
398
+ it "returns 'user:password' for #userinfo" do
399
+ @uri.userinfo.should == "user:password"
400
+ end
401
+
402
+ it "returns 'user:password' for #normalized_userinfo" do
403
+ @uri.normalized_userinfo.should == "user:password"
404
+ end
405
+
406
+ it "returns 'example.com' for #host" do
407
+ @uri.host.should == "example.com"
408
+ end
409
+
410
+ it "returns 'example.com' for #normalized_host" do
411
+ @uri.normalized_host.should == "example.com"
412
+ end
413
+
414
+ it "returns 'user:password@example.com:8080' for #authority" do
415
+ @uri.authority.should == "user:password@example.com:8080"
416
+ end
417
+
418
+ it "returns 'user:password@example.com:8080' for #normalized_authority" do
419
+ @uri.normalized_authority.should == "user:password@example.com:8080"
420
+ end
421
+
422
+ it "returns 8080 for #port" do
423
+ @uri.port.should == 8080
424
+ end
425
+
426
+ it "returns 8080 for #normalized_port" do
427
+ @uri.normalized_port.should == 8080
428
+ end
429
+
430
+ it "returns 80 for #default_port" do
431
+ @uri.default_port.should == 80
432
+ end
433
+
434
+ it "returns 'http://user:password@example.com:8080' for #site" do
435
+ @uri.site.should == "http://user:password@example.com:8080"
436
+ end
437
+
438
+ it "returns 'http://user:password@example.com:8080' for #normalized_site" do
439
+ @uri.normalized_site.should == "http://user:password@example.com:8080"
440
+ end
441
+
442
+ it "returns '/path' for #path" do
443
+ @uri.path.should == "/path"
444
+ end
445
+
446
+ it "returns '/path' for #normalized_path" do
447
+ @uri.normalized_path.should == "/path"
448
+ end
449
+
450
+ it "returns 'query=value' for #query" do
451
+ @uri.query.should == "query=value"
452
+ end
453
+
454
+ it "returns 'query=value' for #normalized_query" do
455
+ @uri.normalized_query.should == "query=value"
456
+ end
457
+
458
+ it "returns 'fragment' for #fragment" do
459
+ @uri.fragment.should == "fragment"
460
+ end
461
+
462
+ it "returns 'fragment' for #normalized_fragment" do
463
+ @uri.normalized_fragment.should == "fragment"
464
+ end
465
+
466
+ it "returns #hash" do
467
+ @uri.hash.should_not be nil
468
+ end
469
+
470
+ it "returns #to_s" do
471
+ @uri.to_s.should ==
472
+ "http://user:password@example.com:8080/path?query=value#fragment"
473
+ end
474
+
475
+ it "should not be empty" do
476
+ @uri.should_not be_empty
477
+ end
478
+
479
+ it "should not be frozen" do
480
+ @uri.should_not be_frozen
481
+ end
482
+
483
+ it "should allow destructive operations" do
484
+ expect { @uri.normalize! }.not_to raise_error
485
+ end
486
+ end
487
+
488
+ describe Addressable::URI, "when parsed from a frozen string" do
489
+ before do
490
+ @uri = Addressable::URI.parse(
491
+ "http://user:password@example.com:8080/path?query=value#fragment".freeze
492
+ )
493
+ end
494
+
495
+ it "returns 'http' for #scheme" do
496
+ @uri.scheme.should == "http"
497
+ end
498
+
499
+ it "returns 'http' for #normalized_scheme" do
500
+ @uri.normalized_scheme.should == "http"
501
+ end
502
+
503
+ it "returns 'user' for #user" do
504
+ @uri.user.should == "user"
505
+ end
506
+
507
+ it "returns 'user' for #normalized_user" do
508
+ @uri.normalized_user.should == "user"
509
+ end
510
+
511
+ it "returns 'password' for #password" do
512
+ @uri.password.should == "password"
513
+ end
514
+
515
+ it "returns 'password' for #normalized_password" do
516
+ @uri.normalized_password.should == "password"
517
+ end
518
+
519
+ it "returns 'user:password' for #userinfo" do
520
+ @uri.userinfo.should == "user:password"
521
+ end
522
+
523
+ it "returns 'user:password' for #normalized_userinfo" do
524
+ @uri.normalized_userinfo.should == "user:password"
525
+ end
526
+
527
+ it "returns 'example.com' for #host" do
528
+ @uri.host.should == "example.com"
529
+ end
530
+
531
+ it "returns 'example.com' for #normalized_host" do
532
+ @uri.normalized_host.should == "example.com"
533
+ end
534
+
535
+ it "returns 'user:password@example.com:8080' for #authority" do
536
+ @uri.authority.should == "user:password@example.com:8080"
537
+ end
538
+
539
+ it "returns 'user:password@example.com:8080' for #normalized_authority" do
540
+ @uri.normalized_authority.should == "user:password@example.com:8080"
541
+ end
542
+
543
+ it "returns 8080 for #port" do
544
+ @uri.port.should == 8080
545
+ end
546
+
547
+ it "returns 8080 for #normalized_port" do
548
+ @uri.normalized_port.should == 8080
549
+ end
550
+
551
+ it "returns 80 for #default_port" do
552
+ @uri.default_port.should == 80
553
+ end
554
+
555
+ it "returns 'http://user:password@example.com:8080' for #site" do
556
+ @uri.site.should == "http://user:password@example.com:8080"
557
+ end
558
+
559
+ it "returns 'http://user:password@example.com:8080' for #normalized_site" do
560
+ @uri.normalized_site.should == "http://user:password@example.com:8080"
561
+ end
562
+
563
+ it "returns '/path' for #path" do
564
+ @uri.path.should == "/path"
565
+ end
566
+
567
+ it "returns '/path' for #normalized_path" do
568
+ @uri.normalized_path.should == "/path"
569
+ end
570
+
571
+ it "returns 'query=value' for #query" do
572
+ @uri.query.should == "query=value"
573
+ end
574
+
575
+ it "returns 'query=value' for #normalized_query" do
576
+ @uri.normalized_query.should == "query=value"
577
+ end
578
+
579
+ it "returns 'fragment' for #fragment" do
580
+ @uri.fragment.should == "fragment"
581
+ end
582
+
583
+ it "returns 'fragment' for #normalized_fragment" do
584
+ @uri.normalized_fragment.should == "fragment"
585
+ end
586
+
587
+ it "returns #hash" do
588
+ @uri.hash.should_not be nil
589
+ end
590
+
591
+ it "returns #to_s" do
592
+ @uri.to_s.should ==
593
+ "http://user:password@example.com:8080/path?query=value#fragment"
594
+ end
595
+
596
+ it "should not be empty" do
597
+ @uri.should_not be_empty
598
+ end
599
+
600
+ it "should not be frozen" do
601
+ @uri.should_not be_frozen
602
+ end
603
+
604
+ it "should allow destructive operations" do
605
+ expect { @uri.normalize! }.not_to raise_error
606
+ end
607
+ end
608
+
221
609
  describe Addressable::URI, "when frozen" do
222
610
  before do
223
611
  @uri = Addressable::URI.new.freeze
@@ -232,7 +620,7 @@ describe Addressable::URI, "when frozen" do
232
620
  end
233
621
 
234
622
  it "returns nil for #user" do
235
- @uri.user .should == nil
623
+ @uri.user.should == nil
236
624
  end
237
625
 
238
626
  it "returns nil for #normalized_user" do
@@ -322,6 +710,161 @@ describe Addressable::URI, "when frozen" do
322
710
  it "returns #to_s" do
323
711
  @uri.to_s.should == ''
324
712
  end
713
+
714
+ it "should be empty" do
715
+ @uri.should be_empty
716
+ end
717
+
718
+ it "should be frozen" do
719
+ @uri.should be_frozen
720
+ end
721
+
722
+ it "should not be frozen after duping" do
723
+ @uri.dup.should_not be_frozen
724
+ end
725
+
726
+ it "should not allow destructive operations" do
727
+ expect { @uri.normalize! }.to raise_error { |error|
728
+ error.message.should match(/can't modify frozen/)
729
+ error.should satisfy { |e| RuntimeError === e || TypeError === e }
730
+ }
731
+ end
732
+ end
733
+
734
+ describe Addressable::URI, "when frozen" do
735
+ before do
736
+ @uri = Addressable::URI.parse(
737
+ "HTTP://example.com.:%38%30/%70a%74%68?a=%31#1%323"
738
+ ).freeze
739
+ end
740
+
741
+ it "returns 'HTTP' for #scheme" do
742
+ @uri.scheme.should == "HTTP"
743
+ end
744
+
745
+ it "returns 'http' for #normalized_scheme" do
746
+ @uri.normalized_scheme.should == "http"
747
+ @uri.normalize.scheme.should == "http"
748
+ end
749
+
750
+ it "returns nil for #user" do
751
+ @uri.user.should == nil
752
+ end
753
+
754
+ it "returns nil for #normalized_user" do
755
+ @uri.normalized_user.should == nil
756
+ end
757
+
758
+ it "returns nil for #password" do
759
+ @uri.password.should == nil
760
+ end
761
+
762
+ it "returns nil for #normalized_password" do
763
+ @uri.normalized_password.should == nil
764
+ end
765
+
766
+ it "returns nil for #userinfo" do
767
+ @uri.userinfo.should == nil
768
+ end
769
+
770
+ it "returns nil for #normalized_userinfo" do
771
+ @uri.normalized_userinfo.should == nil
772
+ end
773
+
774
+ it "returns 'example.com.' for #host" do
775
+ @uri.host.should == "example.com."
776
+ end
777
+
778
+ it "returns nil for #normalized_host" do
779
+ @uri.normalized_host.should == "example.com"
780
+ @uri.normalize.host.should == "example.com"
781
+ end
782
+
783
+ it "returns 'example.com.:80' for #authority" do
784
+ @uri.authority.should == "example.com.:80"
785
+ end
786
+
787
+ it "returns 'example.com:80' for #normalized_authority" do
788
+ @uri.normalized_authority.should == "example.com"
789
+ @uri.normalize.authority.should == "example.com"
790
+ end
791
+
792
+ it "returns 80 for #port" do
793
+ @uri.port.should == 80
794
+ end
795
+
796
+ it "returns nil for #normalized_port" do
797
+ @uri.normalized_port.should == nil
798
+ @uri.normalize.port.should == nil
799
+ end
800
+
801
+ it "returns 80 for #default_port" do
802
+ @uri.default_port.should == 80
803
+ end
804
+
805
+ it "returns 'HTTP://example.com.:80' for #site" do
806
+ @uri.site.should == "HTTP://example.com.:80"
807
+ end
808
+
809
+ it "returns 'http://example.com' for #normalized_site" do
810
+ @uri.normalized_site.should == "http://example.com"
811
+ @uri.normalize.site.should == "http://example.com"
812
+ end
813
+
814
+ it "returns '/%70a%74%68' for #path" do
815
+ @uri.path.should == "/%70a%74%68"
816
+ end
817
+
818
+ it "returns '/path' for #normalized_path" do
819
+ @uri.normalized_path.should == "/path"
820
+ @uri.normalize.path.should == "/path"
821
+ end
822
+
823
+ it "returns 'a=%31' for #query" do
824
+ @uri.query.should == "a=%31"
825
+ end
826
+
827
+ it "returns 'a=1' for #normalized_query" do
828
+ @uri.normalized_query.should == "a=1"
829
+ @uri.normalize.query.should == "a=1"
830
+ end
831
+
832
+ it "returns '1%323' for #fragment" do
833
+ @uri.fragment.should == "1%323"
834
+ end
835
+
836
+ it "returns '123' for #normalized_fragment" do
837
+ @uri.normalized_fragment.should == "123"
838
+ @uri.normalize.fragment.should == "123"
839
+ end
840
+
841
+ it "returns #hash" do
842
+ @uri.hash.should_not be nil
843
+ end
844
+
845
+ it "returns #to_s" do
846
+ @uri.to_s.should == 'HTTP://example.com.:80/%70a%74%68?a=%31#1%323'
847
+ @uri.normalize.to_s.should == 'http://example.com/path?a=1#123'
848
+ end
849
+
850
+ it "should not be empty" do
851
+ @uri.should_not be_empty
852
+ end
853
+
854
+ it "should be frozen" do
855
+ @uri.should be_frozen
856
+ end
857
+
858
+ it "should not be frozen after duping" do
859
+ @uri.dup.should_not be_frozen
860
+ end
861
+
862
+ it "should not allow destructive operations" do
863
+ expect { @uri.normalize! }.to raise_error { |error|
864
+ error.message.should match(/can't modify frozen/)
865
+ error.should satisfy { |e| RuntimeError === e || TypeError === e }
866
+ }
867
+ end
325
868
  end
326
869
 
327
870
  describe Addressable::URI, "when created from string components" do
@@ -463,7 +1006,7 @@ end
463
1006
  describe Addressable::URI, "when parsed from something that looks " +
464
1007
  "like a URI object" do
465
1008
  it "should parse without error" do
466
- uri = Addressable::URI.parse(URI::HTTP.new("http://example.com/"))
1009
+ uri = Addressable::URI.parse(Fake::URI::HTTP.new("http://example.com/"))
467
1010
  (lambda do
468
1011
  Addressable::URI.parse(uri)
469
1012
  end).should_not raise_error
@@ -696,6 +1239,50 @@ describe Addressable::URI, "when parsed from " +
696
1239
  end
697
1240
  end
698
1241
 
1242
+ # Section 2 of RFC 6068
1243
+ describe Addressable::URI, "when parsed from " +
1244
+ "'mailto:?to=addr1@an.example,addr2@an.example'" do
1245
+ before do
1246
+ @uri = Addressable::URI.parse(
1247
+ "mailto:?to=addr1@an.example,addr2@an.example"
1248
+ )
1249
+ end
1250
+
1251
+ it "should use the 'mailto' scheme" do
1252
+ @uri.scheme.should == "mailto"
1253
+ end
1254
+
1255
+ it "should not be considered to be ip-based" do
1256
+ @uri.should_not be_ip_based
1257
+ end
1258
+
1259
+ it "should not have an inferred_port" do
1260
+ @uri.inferred_port.should == nil
1261
+ end
1262
+
1263
+ it "should have a path of ''" do
1264
+ @uri.path.should == ""
1265
+ end
1266
+
1267
+ it "should not have a request URI" do
1268
+ @uri.request_uri.should == nil
1269
+ end
1270
+
1271
+ it "should have the To: field value parameterized" do
1272
+ @uri.query_values(Hash)["to"].should == (
1273
+ "addr1@an.example,addr2@an.example"
1274
+ )
1275
+ end
1276
+
1277
+ it "should be considered to be in normal form" do
1278
+ @uri.normalize.should be_eql(@uri)
1279
+ end
1280
+
1281
+ it "should have a 'null' origin" do
1282
+ @uri.origin.should == 'null'
1283
+ end
1284
+ end
1285
+
699
1286
  # Section 1.1.2 of RFC 3986
700
1287
  describe Addressable::URI, "when parsed from " +
701
1288
  "'news:comp.infosystems.www.servers.unix'" do
@@ -1050,9 +1637,9 @@ describe Addressable::URI, "when parsed from " +
1050
1637
  Addressable::URI.parse("/path/")
1051
1638
  end
1052
1639
 
1053
- it "should have a route of '/' from 'http://example.com/path/'" do
1640
+ it "should have a route of '..' from 'http://example.com/path/'" do
1054
1641
  @uri.route_from("http://example.com/path/").should ==
1055
- Addressable::URI.parse("/")
1642
+ Addressable::URI.parse("..")
1056
1643
  end
1057
1644
 
1058
1645
  it "should have a route of '#' to 'http://example.com/'" do
@@ -1257,6 +1844,28 @@ describe Addressable::URI, "when parsing IPv6 addresses" do
1257
1844
  end
1258
1845
  end
1259
1846
 
1847
+ describe Addressable::URI, "when parsing IPv6 address" do
1848
+ subject { Addressable::URI.parse("http://[3ffe:1900:4545:3:200:f8ff:fe21:67cf]/") }
1849
+ its(:host) { should == '[3ffe:1900:4545:3:200:f8ff:fe21:67cf]' }
1850
+ its(:hostname) { should == '3ffe:1900:4545:3:200:f8ff:fe21:67cf' }
1851
+ end
1852
+
1853
+ describe Addressable::URI, "when assigning IPv6 address" do
1854
+ it "should allow to set bare IPv6 address as hostname" do
1855
+ uri = Addressable::URI.parse("http://[::1]/")
1856
+ uri.hostname = '3ffe:1900:4545:3:200:f8ff:fe21:67cf'
1857
+ uri.to_s.should == 'http://[3ffe:1900:4545:3:200:f8ff:fe21:67cf]/'
1858
+ end
1859
+
1860
+ it "should not allow to set bare IPv6 address as host" do
1861
+ uri = Addressable::URI.parse("http://[::1]/")
1862
+ pending "not checked"
1863
+ (lambda do
1864
+ uri.host = '3ffe:1900:4545:3:200:f8ff:fe21:67cf'
1865
+ end).should raise_error(Addressable::URI::InvalidURIError)
1866
+ end
1867
+ end
1868
+
1260
1869
  describe Addressable::URI, "when parsing IPvFuture addresses" do
1261
1870
  it "should not raise an error for " +
1262
1871
  "'http://[v9.3ffe:1900:4545:3:200:f8ff:fe21:67cf]/'" do
@@ -1924,10 +2533,10 @@ describe Addressable::URI, "when parsed from " +
1924
2533
  Addressable::URI.parse("http://example.com:8080/")
1925
2534
  end
1926
2535
 
1927
- it "should have a route of '/' from " +
2536
+ it "should have a route of '../../' from " +
1928
2537
  "'http://example.com:8080/path/to/'" do
1929
2538
  @uri.route_from("http://example.com:8080/path/to/").should ==
1930
- Addressable::URI.parse("/")
2539
+ Addressable::URI.parse("../../")
1931
2540
  end
1932
2541
 
1933
2542
  it "should have a route of 'http://example.com:8080/' from " +
@@ -2208,6 +2817,25 @@ describe Addressable::URI, "when parsed from " +
2208
2817
  Addressable::URI.parse("resource/")
2209
2818
  end
2210
2819
 
2820
+ it "should have a route of '../' from " +
2821
+ "'http://example.com/path/to/resource/sub'" do
2822
+ @uri.route_from("http://example.com/path/to/resource/sub").should ==
2823
+ Addressable::URI.parse("../")
2824
+ end
2825
+
2826
+
2827
+ it "should have a route of 'resource/' from " +
2828
+ "'http://example.com/path/to/another'" do
2829
+ @uri.route_from("http://example.com/path/to/another").should ==
2830
+ Addressable::URI.parse("resource/")
2831
+ end
2832
+
2833
+ it "should have a route of 'resource/' from " +
2834
+ "'http://example.com/path/to/res'" do
2835
+ @uri.route_from("http://example.com/path/to/res").should ==
2836
+ Addressable::URI.parse("resource/")
2837
+ end
2838
+
2211
2839
  it "should have a route of 'resource/' from " +
2212
2840
  "'http://example.com:80/path/to/'" do
2213
2841
  @uri.route_from("http://example.com:80/path/to/").should ==
@@ -2226,10 +2854,10 @@ describe Addressable::URI, "when parsed from " +
2226
2854
  Addressable::URI.parse("http://example.com/path/to/resource/")
2227
2855
  end
2228
2856
 
2229
- it "should have a route of '/path/to/resource/' from " +
2857
+ it "should have a route of '../../path/to/resource/' from " +
2230
2858
  "'http://example.com/to/resource/'" do
2231
2859
  @uri.route_from("http://example.com/to/resource/").should ==
2232
- Addressable::URI.parse("/path/to/resource/")
2860
+ Addressable::URI.parse("../../path/to/resource/")
2233
2861
  end
2234
2862
 
2235
2863
  it "should correctly convert to a hash" do
@@ -2768,13 +3396,13 @@ describe Addressable::URI, "when parsed from " +
2768
3396
  @uri.normalize.should be_eql(@uri)
2769
3397
  end
2770
3398
 
2771
- it "should have a route of '/path/' to " +
3399
+ it "should have a route of '../../' to " +
2772
3400
  "'http://user:pass@example.com/path/'" do
2773
3401
  @uri.route_to("http://user:pass@example.com/path/").should ==
2774
- Addressable::URI.parse("/path/")
3402
+ Addressable::URI.parse("../../")
2775
3403
  end
2776
3404
 
2777
- it "should have a route of '/path/to/resource?query=x#fragment' " +
3405
+ it "should have a route of 'to/resource?query=x#fragment' " +
2778
3406
  "from 'http://user:pass@example.com/path/'" do
2779
3407
  @uri.route_from("http://user:pass@example.com/path/").should ==
2780
3408
  Addressable::URI.parse("to/resource?query=x#fragment")
@@ -3102,6 +3730,27 @@ describe Addressable::URI, "when parsed from " +
3102
3730
  end
3103
3731
  end
3104
3732
 
3733
+ describe Addressable::URI, "when parsed from " +
3734
+ "'http://example.com/?q='one;two'&x=1'" do
3735
+ before do
3736
+ @uri = Addressable::URI.parse("http://example.com/?q='one;two'&x=1")
3737
+ end
3738
+
3739
+ it "should have a query of 'q='one;two'&x=1'" do
3740
+ @uri.query.should == "q='one;two'&x=1"
3741
+ end
3742
+
3743
+ it "should have query_values of {\"q\" => \"'one;two'\", \"x\" => \"1\"}" do
3744
+ @uri.query_values.should == {"q" => "'one;two'", "x" => "1"}
3745
+ end
3746
+
3747
+ it "should escape the ';' character when normalizing to avoid ambiguity " +
3748
+ "with the W3C HTML 4.01 specification" do
3749
+ # HTML 4.01 Section B.2.2
3750
+ @uri.normalize.query.should == "q='one%3Btwo'&x=1"
3751
+ end
3752
+ end
3753
+
3105
3754
  describe Addressable::URI, "when parsed from " +
3106
3755
  "'http://example.com/?&&x=b'" do
3107
3756
  before do
@@ -5159,3 +5808,29 @@ describe Addressable::URI, "when assigning path values" do
5159
5808
  end).should_not raise_error(Addressable::URI::InvalidURIError)
5160
5809
  end
5161
5810
  end
5811
+
5812
+ describe Addressable::URI, "when initializing a subclass of Addressable::URI" do
5813
+ before do
5814
+ @uri = Class.new(Addressable::URI).new
5815
+ end
5816
+
5817
+ it "should have the same class after being parsed" do
5818
+ @uri.class.should == Addressable::URI.parse(@uri).class
5819
+ end
5820
+
5821
+ it "should have the same class as its duplicate" do
5822
+ @uri.class.should == @uri.dup.class
5823
+ end
5824
+
5825
+ it "should have the same class after being normalized" do
5826
+ @uri.class.should == @uri.normalize.class
5827
+ end
5828
+
5829
+ it "should have the same class after being merged" do
5830
+ @uri.class.should == @uri.merge(:path => 'path').class
5831
+ end
5832
+
5833
+ it "should have the same class after being joined" do
5834
+ @uri.class.should == @uri.join('path').class
5835
+ end
5836
+ end