addressable 2.2.8 → 2.3.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of addressable might be problematic. Click here for more details.
- data/CHANGELOG.md +14 -0
- data/README.md +7 -3
- data/Rakefile +2 -2
- data/data/unicode.data +0 -0
- data/lib/addressable/idna/pure.rb +7 -4235
- data/lib/addressable/template.rb +334 -543
- data/lib/addressable/uri.rb +117 -160
- data/lib/addressable/version.rb +2 -2
- data/spec/addressable/idna_spec.rb +15 -0
- data/spec/addressable/template_spec.rb +920 -2063
- data/spec/addressable/uri_spec.rb +265 -129
- metadata +5 -27
- data/Gemfile.lock +0 -35
@@ -150,6 +150,14 @@ describe Addressable::URI, "when created with a scheme but no hierarchical " +
|
|
150
150
|
end
|
151
151
|
end
|
152
152
|
|
153
|
+
describe Addressable::URI, "when created with an invalid host" do
|
154
|
+
it "should raise an error" do
|
155
|
+
(lambda do
|
156
|
+
Addressable::URI.new(:host => "<invalid>")
|
157
|
+
end).should raise_error(Addressable::URI::InvalidURIError)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
153
161
|
describe Addressable::URI, "when created from nil components" do
|
154
162
|
before do
|
155
163
|
@uri = Addressable::URI.new
|
@@ -167,6 +175,10 @@ describe Addressable::URI, "when created from nil components" do
|
|
167
175
|
@uri.to_s.should == ""
|
168
176
|
end
|
169
177
|
|
178
|
+
it "should have a nil default port" do
|
179
|
+
@uri.default_port.should == nil
|
180
|
+
end
|
181
|
+
|
170
182
|
it "should raise an error if the scheme is set to whitespace" do
|
171
183
|
(lambda do
|
172
184
|
@uri.scheme = "\t \n"
|
@@ -267,6 +279,10 @@ describe Addressable::URI, "when frozen" do
|
|
267
279
|
@uri.normalized_port.should == nil
|
268
280
|
end
|
269
281
|
|
282
|
+
it "returns nil for #default_port" do
|
283
|
+
@uri.default_port.should == nil
|
284
|
+
end
|
285
|
+
|
270
286
|
it "returns nil for #site" do
|
271
287
|
@uri.site.should == nil
|
272
288
|
end
|
@@ -359,6 +375,7 @@ describe Addressable::URI, "when created with an authority and no port" do
|
|
359
375
|
|
360
376
|
it "should not infer a port" do
|
361
377
|
@uri.port.should == nil
|
378
|
+
@uri.default_port.should == nil
|
362
379
|
@uri.inferred_port.should == nil
|
363
380
|
end
|
364
381
|
|
@@ -506,6 +523,10 @@ describe Addressable::URI, "when parsed from " +
|
|
506
523
|
@uri.host.should == "ftp.is.co.za"
|
507
524
|
end
|
508
525
|
|
526
|
+
it "should have inferred_port of 21" do
|
527
|
+
@uri.inferred_port.should == 21
|
528
|
+
end
|
529
|
+
|
509
530
|
it "should have a path of '/rfc/rfc1808.txt'" do
|
510
531
|
@uri.path.should == "/rfc/rfc1808.txt"
|
511
532
|
end
|
@@ -542,6 +563,10 @@ describe Addressable::URI, "when parsed from " +
|
|
542
563
|
@uri.host.should == "www.ietf.org"
|
543
564
|
end
|
544
565
|
|
566
|
+
it "should have inferred_port of 80" do
|
567
|
+
@uri.inferred_port.should == 80
|
568
|
+
end
|
569
|
+
|
545
570
|
it "should have a path of '/rfc/rfc2396.txt'" do
|
546
571
|
@uri.path.should == "/rfc/rfc2396.txt"
|
547
572
|
end
|
@@ -588,6 +613,10 @@ describe Addressable::URI, "when parsed from " +
|
|
588
613
|
@uri.host.should == "[2001:db8::7]"
|
589
614
|
end
|
590
615
|
|
616
|
+
it "should have inferred_port of 389" do
|
617
|
+
@uri.inferred_port.should == 389
|
618
|
+
end
|
619
|
+
|
591
620
|
it "should have a path of '/c=GB'" do
|
592
621
|
@uri.path.should == "/c=GB"
|
593
622
|
end
|
@@ -646,6 +675,10 @@ describe Addressable::URI, "when parsed from " +
|
|
646
675
|
@uri.should_not be_ip_based
|
647
676
|
end
|
648
677
|
|
678
|
+
it "should not have an inferred_port" do
|
679
|
+
@uri.inferred_port.should == nil
|
680
|
+
end
|
681
|
+
|
649
682
|
it "should have a path of 'John.Doe@example.com'" do
|
650
683
|
@uri.path.should == "John.Doe@example.com"
|
651
684
|
end
|
@@ -674,6 +707,10 @@ describe Addressable::URI, "when parsed from " +
|
|
674
707
|
@uri.scheme.should == "news"
|
675
708
|
end
|
676
709
|
|
710
|
+
it "should not have an inferred_port" do
|
711
|
+
@uri.inferred_port.should == nil
|
712
|
+
end
|
713
|
+
|
677
714
|
it "should not be considered to be ip-based" do
|
678
715
|
@uri.should_not be_ip_based
|
679
716
|
end
|
@@ -710,6 +747,10 @@ describe Addressable::URI, "when parsed from " +
|
|
710
747
|
@uri.should_not be_ip_based
|
711
748
|
end
|
712
749
|
|
750
|
+
it "should not have an inferred_port" do
|
751
|
+
@uri.inferred_port.should == nil
|
752
|
+
end
|
753
|
+
|
713
754
|
it "should have a path of '+1-816-555-1212'" do
|
714
755
|
@uri.path.should == "+1-816-555-1212"
|
715
756
|
end
|
@@ -742,10 +783,18 @@ describe Addressable::URI, "when parsed from " +
|
|
742
783
|
@uri.host.should == "192.0.2.16"
|
743
784
|
end
|
744
785
|
|
745
|
-
it "should have a port of
|
786
|
+
it "should have a port of 80" do
|
746
787
|
@uri.port.should == 80
|
747
788
|
end
|
748
789
|
|
790
|
+
it "should have a inferred_port of 80" do
|
791
|
+
@uri.inferred_port.should == 80
|
792
|
+
end
|
793
|
+
|
794
|
+
it "should have a default_port of 23" do
|
795
|
+
@uri.default_port.should == 23
|
796
|
+
end
|
797
|
+
|
749
798
|
it "should be considered to be ip-based" do
|
750
799
|
@uri.should be_ip_based
|
751
800
|
end
|
@@ -779,6 +828,10 @@ describe Addressable::URI, "when parsed from " +
|
|
779
828
|
@uri.scheme.should == "urn"
|
780
829
|
end
|
781
830
|
|
831
|
+
it "should not have an inferred_port" do
|
832
|
+
@uri.inferred_port.should == nil
|
833
|
+
end
|
834
|
+
|
782
835
|
it "should not be considered to be ip-based" do
|
783
836
|
@uri.should_not be_ip_based
|
784
837
|
end
|
@@ -801,6 +854,41 @@ describe Addressable::URI, "when parsed from " +
|
|
801
854
|
end
|
802
855
|
end
|
803
856
|
|
857
|
+
describe Addressable::URI, "when heuristically parsed from " +
|
858
|
+
"'192.0.2.16:8000/path'" do
|
859
|
+
before do
|
860
|
+
@uri = Addressable::URI.heuristic_parse("192.0.2.16:8000/path")
|
861
|
+
end
|
862
|
+
|
863
|
+
it "should use the 'http' scheme" do
|
864
|
+
@uri.scheme.should == "http"
|
865
|
+
end
|
866
|
+
|
867
|
+
it "should have a host of '192.0.2.16'" do
|
868
|
+
@uri.host.should == "192.0.2.16"
|
869
|
+
end
|
870
|
+
|
871
|
+
it "should have a port of '8000'" do
|
872
|
+
@uri.port.should == 8000
|
873
|
+
end
|
874
|
+
|
875
|
+
it "should be considered to be ip-based" do
|
876
|
+
@uri.should be_ip_based
|
877
|
+
end
|
878
|
+
|
879
|
+
it "should have a path of '/path'" do
|
880
|
+
@uri.path.should == "/path"
|
881
|
+
end
|
882
|
+
|
883
|
+
it "should be considered to be in normal form" do
|
884
|
+
@uri.normalize.should be_eql(@uri)
|
885
|
+
end
|
886
|
+
|
887
|
+
it "should have an origin of 'http://192.0.2.16:8000'" do
|
888
|
+
@uri.origin.should == 'http://192.0.2.16:8000'
|
889
|
+
end
|
890
|
+
end
|
891
|
+
|
804
892
|
describe Addressable::URI, "when parsed from " +
|
805
893
|
"'http://example.com'" do
|
806
894
|
before do
|
@@ -1135,6 +1223,74 @@ describe Addressable::URI, "when parsed from " +
|
|
1135
1223
|
end
|
1136
1224
|
end
|
1137
1225
|
|
1226
|
+
describe Addressable::URI, "when parsing IPv6 addresses" do
|
1227
|
+
it "should not raise an error for " +
|
1228
|
+
"'http://[3ffe:1900:4545:3:200:f8ff:fe21:67cf]/'" do
|
1229
|
+
Addressable::URI.parse("http://[3ffe:1900:4545:3:200:f8ff:fe21:67cf]/")
|
1230
|
+
end
|
1231
|
+
|
1232
|
+
it "should not raise an error for " +
|
1233
|
+
"'http://[fe80:0:0:0:200:f8ff:fe21:67cf]/'" do
|
1234
|
+
Addressable::URI.parse("http://[fe80:0:0:0:200:f8ff:fe21:67cf]/")
|
1235
|
+
end
|
1236
|
+
|
1237
|
+
it "should not raise an error for " +
|
1238
|
+
"'http://[fe80::200:f8ff:fe21:67cf]/'" do
|
1239
|
+
Addressable::URI.parse("http://[fe80::200:f8ff:fe21:67cf]/")
|
1240
|
+
end
|
1241
|
+
|
1242
|
+
it "should not raise an error for " +
|
1243
|
+
"'http://[::1]/'" do
|
1244
|
+
Addressable::URI.parse("http://[::1]/")
|
1245
|
+
end
|
1246
|
+
|
1247
|
+
it "should not raise an error for " +
|
1248
|
+
"'http://[fe80::1]/'" do
|
1249
|
+
Addressable::URI.parse("http://[fe80::1]/")
|
1250
|
+
end
|
1251
|
+
|
1252
|
+
it "should raise an error for " +
|
1253
|
+
"'http://[<invalid>]/'" do
|
1254
|
+
(lambda do
|
1255
|
+
Addressable::URI.parse("http://[<invalid>]/")
|
1256
|
+
end).should raise_error(Addressable::URI::InvalidURIError)
|
1257
|
+
end
|
1258
|
+
end
|
1259
|
+
|
1260
|
+
describe Addressable::URI, "when parsing IPvFuture addresses" do
|
1261
|
+
it "should not raise an error for " +
|
1262
|
+
"'http://[v9.3ffe:1900:4545:3:200:f8ff:fe21:67cf]/'" do
|
1263
|
+
Addressable::URI.parse("http://[v9.3ffe:1900:4545:3:200:f8ff:fe21:67cf]/")
|
1264
|
+
end
|
1265
|
+
|
1266
|
+
it "should not raise an error for " +
|
1267
|
+
"'http://[vff.fe80:0:0:0:200:f8ff:fe21:67cf]/'" do
|
1268
|
+
Addressable::URI.parse("http://[vff.fe80:0:0:0:200:f8ff:fe21:67cf]/")
|
1269
|
+
end
|
1270
|
+
|
1271
|
+
it "should not raise an error for " +
|
1272
|
+
"'http://[v12.fe80::200:f8ff:fe21:67cf]/'" do
|
1273
|
+
Addressable::URI.parse("http://[v12.fe80::200:f8ff:fe21:67cf]/")
|
1274
|
+
end
|
1275
|
+
|
1276
|
+
it "should not raise an error for " +
|
1277
|
+
"'http://[va0.::1]/'" do
|
1278
|
+
Addressable::URI.parse("http://[va0.::1]/")
|
1279
|
+
end
|
1280
|
+
|
1281
|
+
it "should not raise an error for " +
|
1282
|
+
"'http://[v255.fe80::1]/'" do
|
1283
|
+
Addressable::URI.parse("http://[v255.fe80::1]/")
|
1284
|
+
end
|
1285
|
+
|
1286
|
+
it "should raise an error for " +
|
1287
|
+
"'http://[v0.<invalid>]/'" do
|
1288
|
+
(lambda do
|
1289
|
+
Addressable::URI.parse("http://[v0.<invalid>]/")
|
1290
|
+
end).should raise_error(Addressable::URI::InvalidURIError)
|
1291
|
+
end
|
1292
|
+
end
|
1293
|
+
|
1138
1294
|
describe Addressable::URI, "when parsed from " +
|
1139
1295
|
"'http://example.com/'" do
|
1140
1296
|
before do
|
@@ -1593,6 +1749,10 @@ describe Addressable::URI, "when parsed from " +
|
|
1593
1749
|
end
|
1594
1750
|
|
1595
1751
|
it "should use port 80" do
|
1752
|
+
@uri.inferred_port.should == 80
|
1753
|
+
end
|
1754
|
+
|
1755
|
+
it "should have explicit port 80" do
|
1596
1756
|
@uri.port.should == 80
|
1597
1757
|
end
|
1598
1758
|
|
@@ -1709,9 +1869,17 @@ describe Addressable::URI, "when parsed from " +
|
|
1709
1869
|
end
|
1710
1870
|
|
1711
1871
|
it "should use port 8080" do
|
1872
|
+
@uri.inferred_port.should == 8080
|
1873
|
+
end
|
1874
|
+
|
1875
|
+
it "should have explicit port 8080" do
|
1712
1876
|
@uri.port.should == 8080
|
1713
1877
|
end
|
1714
1878
|
|
1879
|
+
it "should have default port 80" do
|
1880
|
+
@uri.default_port.should == 80
|
1881
|
+
end
|
1882
|
+
|
1715
1883
|
it "should have a path of '/'" do
|
1716
1884
|
@uri.path.should == "/"
|
1717
1885
|
end
|
@@ -2757,11 +2925,11 @@ describe Addressable::URI, "when parsed from " +
|
|
2757
2925
|
end
|
2758
2926
|
|
2759
2927
|
it "should have the correct query string after hash assignment" do
|
2760
|
-
@uri.query_values = {"?uestion mark"=>"=sign", "hello"=>"g\xC3\xBCnther"}
|
2928
|
+
@uri.query_values = {"?uestion mark" => "=sign", "hello" => "g\xC3\xBCnther"}
|
2761
2929
|
@uri.query.split("&").should include("%3Fuestion%20mark=%3Dsign")
|
2762
2930
|
@uri.query.split("&").should include("hello=g%C3%BCnther")
|
2763
2931
|
@uri.query_values.should == {
|
2764
|
-
"?uestion mark"=>"=sign", "hello"=>"g\xC3\xBCnther"
|
2932
|
+
"?uestion mark" => "=sign", "hello" => "g\xC3\xBCnther"
|
2765
2933
|
}
|
2766
2934
|
end
|
2767
2935
|
|
@@ -2770,8 +2938,9 @@ describe Addressable::URI, "when parsed from " +
|
|
2770
2938
|
@uri.query.split("&").should include("flag%3F1")
|
2771
2939
|
@uri.query.split("&").should include("fl%3Dag2")
|
2772
2940
|
@uri.query.split("&").should include("flag3")
|
2773
|
-
@uri.query_values.should ==
|
2774
|
-
|
2941
|
+
@uri.query_values(Array).sort.should == [["fl=ag2"], ["flag3"], ["flag?1"]]
|
2942
|
+
@uri.query_values(Hash).should == {
|
2943
|
+
'flag?1' => nil, 'fl=ag2' => nil, 'flag3' => nil
|
2775
2944
|
}
|
2776
2945
|
end
|
2777
2946
|
|
@@ -2960,7 +3129,7 @@ describe Addressable::URI, "when parsed from " +
|
|
2960
3129
|
end
|
2961
3130
|
|
2962
3131
|
it "should have query_values of {'q' => true, 'x' => 'b'}" do
|
2963
|
-
@uri.query_values.should == {'q' =>
|
3132
|
+
@uri.query_values.should == {'q' => nil, 'x' => 'b'}
|
2964
3133
|
end
|
2965
3134
|
end
|
2966
3135
|
|
@@ -3039,6 +3208,10 @@ describe Addressable::URI, "when parsed from " +
|
|
3039
3208
|
@uri.host.should == "example.com"
|
3040
3209
|
end
|
3041
3210
|
|
3211
|
+
it "should have default_port 80" do
|
3212
|
+
@uri.default_port.should == 80
|
3213
|
+
end
|
3214
|
+
|
3042
3215
|
it "should use port 80" do
|
3043
3216
|
@uri.inferred_port.should == 80
|
3044
3217
|
end
|
@@ -3469,17 +3642,10 @@ describe Addressable::URI, "when parsed from '?'" do
|
|
3469
3642
|
@uri = Addressable::URI.parse("?")
|
3470
3643
|
end
|
3471
3644
|
|
3472
|
-
it "should have the correct
|
3645
|
+
it "should have the correct return type" do
|
3473
3646
|
@uri.query_values.should == {}
|
3474
|
-
@uri.query_values(
|
3475
|
-
|
3476
|
-
|
3477
|
-
it "should have the correct dot notation query values" do
|
3478
|
-
@uri.query_values(:notation => :dot).should == {}
|
3479
|
-
end
|
3480
|
-
|
3481
|
-
it "should have the correct flat notation query values" do
|
3482
|
-
@uri.query_values(:notation => :flat).should == {}
|
3647
|
+
@uri.query_values(Hash).should == {}
|
3648
|
+
@uri.query_values(Array).should == []
|
3483
3649
|
end
|
3484
3650
|
|
3485
3651
|
it "should have a 'null' origin" do
|
@@ -3496,14 +3662,14 @@ describe Addressable::URI, "when parsed from '?one=1&two=2&three=3'" do
|
|
3496
3662
|
@uri.query_values.should == {"one" => "1", "two" => "2", "three" => "3"}
|
3497
3663
|
end
|
3498
3664
|
|
3499
|
-
it "should raise an error for invalid
|
3665
|
+
it "should raise an error for invalid return type values" do
|
3500
3666
|
(lambda do
|
3501
|
-
@uri.query_values(
|
3667
|
+
@uri.query_values(Fixnum)
|
3502
3668
|
end).should raise_error(ArgumentError)
|
3503
3669
|
end
|
3504
3670
|
|
3505
|
-
it "should have the correct
|
3506
|
-
@uri.query_values(
|
3671
|
+
it "should have the correct array query values" do
|
3672
|
+
@uri.query_values(Array).should == [
|
3507
3673
|
["one", "1"], ["two", "2"], ["three", "3"]
|
3508
3674
|
]
|
3509
3675
|
end
|
@@ -3522,8 +3688,8 @@ describe Addressable::URI, "when parsed from '?one=1=uno&two=2=dos'" do
|
|
3522
3688
|
@uri.query_values.should == {"one" => "1=uno", "two" => "2=dos"}
|
3523
3689
|
end
|
3524
3690
|
|
3525
|
-
it "should have the correct
|
3526
|
-
@uri.query_values(
|
3691
|
+
it "should have the correct array query values" do
|
3692
|
+
@uri.query_values(Array).should == [
|
3527
3693
|
["one", "1=uno"], ["two", "2=dos"]
|
3528
3694
|
]
|
3529
3695
|
end
|
@@ -3535,17 +3701,11 @@ describe Addressable::URI, "when parsed from '?one[two][three]=four'" do
|
|
3535
3701
|
end
|
3536
3702
|
|
3537
3703
|
it "should have the correct query values" do
|
3538
|
-
@uri.query_values.should == {"one
|
3539
|
-
end
|
3540
|
-
|
3541
|
-
it "should have the correct flat notation query values" do
|
3542
|
-
@uri.query_values(:notation => :flat).should == {
|
3543
|
-
"one[two][three]" => "four"
|
3544
|
-
}
|
3704
|
+
@uri.query_values.should == {"one[two][three]" => "four"}
|
3545
3705
|
end
|
3546
3706
|
|
3547
|
-
it "should have the correct
|
3548
|
-
@uri.query_values(
|
3707
|
+
it "should have the correct array query values" do
|
3708
|
+
@uri.query_values(Array).should == [
|
3549
3709
|
["one[two][three]", "four"]
|
3550
3710
|
]
|
3551
3711
|
end
|
@@ -3556,20 +3716,14 @@ describe Addressable::URI, "when parsed from '?one.two.three=four'" do
|
|
3556
3716
|
@uri = Addressable::URI.parse("?one.two.three=four")
|
3557
3717
|
end
|
3558
3718
|
|
3559
|
-
it "should have the correct
|
3560
|
-
@uri.query_values
|
3561
|
-
"one" => {"two" => {"three" => "four"}}
|
3562
|
-
}
|
3563
|
-
end
|
3564
|
-
|
3565
|
-
it "should have the correct flat notation query values" do
|
3566
|
-
@uri.query_values(:notation => :flat).should == {
|
3719
|
+
it "should have the correct query values" do
|
3720
|
+
@uri.query_values.should == {
|
3567
3721
|
"one.two.three" => "four"
|
3568
3722
|
}
|
3569
3723
|
end
|
3570
3724
|
|
3571
|
-
it "should have the correct
|
3572
|
-
@uri.query_values(
|
3725
|
+
it "should have the correct array query values" do
|
3726
|
+
@uri.query_values(Array).should == [
|
3573
3727
|
["one.two.three", "four"]
|
3574
3728
|
]
|
3575
3729
|
end
|
@@ -3581,21 +3735,14 @@ describe Addressable::URI, "when parsed from " +
|
|
3581
3735
|
@uri = Addressable::URI.parse("?one[two][three]=four&one[two][five]=six")
|
3582
3736
|
end
|
3583
3737
|
|
3584
|
-
it "should have the correct
|
3585
|
-
@uri.query_values
|
3586
|
-
"one
|
3587
|
-
}
|
3588
|
-
end
|
3589
|
-
|
3590
|
-
it "should have the correct flat notation query values" do
|
3591
|
-
@uri.query_values(:notation => :flat).should == {
|
3592
|
-
"one[two][three]" => "four",
|
3593
|
-
"one[two][five]" => "six"
|
3738
|
+
it "should have the correct query values" do
|
3739
|
+
@uri.query_values.should == {
|
3740
|
+
"one[two][three]" => "four", "one[two][five]" => "six"
|
3594
3741
|
}
|
3595
3742
|
end
|
3596
3743
|
|
3597
|
-
it "should have the correct
|
3598
|
-
@uri.query_values(
|
3744
|
+
it "should have the correct array query values" do
|
3745
|
+
@uri.query_values(Array).should == [
|
3599
3746
|
["one[two][three]", "four"], ["one[two][five]", "six"]
|
3600
3747
|
]
|
3601
3748
|
end
|
@@ -3607,21 +3754,14 @@ describe Addressable::URI, "when parsed from " +
|
|
3607
3754
|
@uri = Addressable::URI.parse("?one.two.three=four&one.two.five=six")
|
3608
3755
|
end
|
3609
3756
|
|
3610
|
-
it "should have the correct
|
3611
|
-
@uri.query_values
|
3612
|
-
"one
|
3613
|
-
}
|
3614
|
-
end
|
3615
|
-
|
3616
|
-
it "should have the correct flat notation query values" do
|
3617
|
-
@uri.query_values(:notation => :flat).should == {
|
3618
|
-
"one.two.three" => "four",
|
3619
|
-
"one.two.five" => "six"
|
3757
|
+
it "should have the correct query values" do
|
3758
|
+
@uri.query_values.should == {
|
3759
|
+
"one.two.three" => "four", "one.two.five" => "six"
|
3620
3760
|
}
|
3621
3761
|
end
|
3622
3762
|
|
3623
|
-
it "should have the correct
|
3624
|
-
@uri.query_values(
|
3763
|
+
it "should have the correct array query values" do
|
3764
|
+
@uri.query_values(Array).should == [
|
3625
3765
|
["one.two.three", "four"], ["one.two.five", "six"]
|
3626
3766
|
]
|
3627
3767
|
end
|
@@ -3635,8 +3775,8 @@ describe Addressable::URI, "when parsed from " +
|
|
3635
3775
|
)
|
3636
3776
|
end
|
3637
3777
|
|
3638
|
-
it "should have correct
|
3639
|
-
@uri.query_values(
|
3778
|
+
it "should have correct array query values" do
|
3779
|
+
@uri.query_values(Array).should ==
|
3640
3780
|
[['one', 'two'], ['one', 'three']]
|
3641
3781
|
end
|
3642
3782
|
end
|
@@ -3649,23 +3789,14 @@ describe Addressable::URI, "when parsed from " +
|
|
3649
3789
|
)
|
3650
3790
|
end
|
3651
3791
|
|
3652
|
-
it "should have
|
3653
|
-
@uri.query_values(
|
3654
|
-
"one" => {"two" => {"three" => ["four", "five"]}}
|
3655
|
-
}
|
3656
|
-
end
|
3657
|
-
|
3658
|
-
it "should raise an error if a key is repeated in the flat notation" do
|
3659
|
-
(lambda do
|
3660
|
-
@uri.query_values(:notation => :flat)
|
3661
|
-
end).should raise_error(ArgumentError)
|
3792
|
+
it "should have correct query values" do
|
3793
|
+
@uri.query_values(Hash).should == {"one[two][three][]" => "five"}
|
3662
3794
|
end
|
3663
3795
|
|
3664
|
-
it "should
|
3665
|
-
|
3666
|
-
|
3667
|
-
|
3668
|
-
end).should_not raise_error
|
3796
|
+
it "should have correct array query values" do
|
3797
|
+
@uri.query_values(Array).should == [
|
3798
|
+
["one[two][three][]", "four"], ["one[two][three][]", "five"]
|
3799
|
+
]
|
3669
3800
|
end
|
3670
3801
|
end
|
3671
3802
|
|
@@ -3677,9 +3808,9 @@ describe Addressable::URI, "when parsed from " +
|
|
3677
3808
|
)
|
3678
3809
|
end
|
3679
3810
|
|
3680
|
-
it "should have the correct
|
3681
|
-
@uri.query_values
|
3682
|
-
"one" =>
|
3811
|
+
it "should have the correct query values" do
|
3812
|
+
@uri.query_values.should == {
|
3813
|
+
"one[two][three][0]" => "four", "one[two][three][1]" => "five"
|
3683
3814
|
}
|
3684
3815
|
end
|
3685
3816
|
end
|
@@ -3692,9 +3823,9 @@ describe Addressable::URI, "when parsed from " +
|
|
3692
3823
|
)
|
3693
3824
|
end
|
3694
3825
|
|
3695
|
-
it "should have the correct
|
3696
|
-
@uri.query_values
|
3697
|
-
"one" =>
|
3826
|
+
it "should have the correct query values" do
|
3827
|
+
@uri.query_values.should == {
|
3828
|
+
"one[two][three][1]" => "four", "one[two][three][0]" => "five"
|
3698
3829
|
}
|
3699
3830
|
end
|
3700
3831
|
end
|
@@ -3707,9 +3838,9 @@ describe Addressable::URI, "when parsed from " +
|
|
3707
3838
|
)
|
3708
3839
|
end
|
3709
3840
|
|
3710
|
-
it "should have the correct
|
3711
|
-
@uri.query_values
|
3712
|
-
"one" =>
|
3841
|
+
it "should have the correct query values" do
|
3842
|
+
@uri.query_values.should == {
|
3843
|
+
"one[two][three][2]" => "four", "one[two][three][1]" => "five"
|
3713
3844
|
}
|
3714
3845
|
end
|
3715
3846
|
end
|
@@ -4780,51 +4911,58 @@ describe Addressable::URI, "when assigning query values" do
|
|
4780
4911
|
|
4781
4912
|
it "should correctly assign {:a => 'a', :b => ['c', 'd', 'e']}" do
|
4782
4913
|
@uri.query_values = {:a => "a", :b => ["c", "d", "e"]}
|
4783
|
-
@uri.query.should == "a=a&b
|
4914
|
+
@uri.query.should == "a=a&b=c&b=d&b=e"
|
4784
4915
|
end
|
4785
4916
|
|
4786
|
-
it "should
|
4787
|
-
|
4788
|
-
|
4917
|
+
it "should raise an error attempting to assign {'a' => {'b' => ['c']}}" do
|
4918
|
+
(lambda do
|
4919
|
+
@uri.query_values = { 'a' => {'b' => ['c'] } }
|
4920
|
+
end).should raise_error(TypeError)
|
4789
4921
|
end
|
4790
4922
|
|
4791
|
-
it "should
|
4792
|
-
|
4793
|
-
|
4923
|
+
it "should raise an error attempting to assign " +
|
4924
|
+
"{:b => '2', :a => {:c => '1'}}" do
|
4925
|
+
(lambda do
|
4926
|
+
@uri.query_values = {:b => '2', :a => {:c => '1'}}
|
4927
|
+
end).should raise_error(TypeError)
|
4794
4928
|
end
|
4795
4929
|
|
4796
|
-
it "should
|
4930
|
+
it "should raise an error attempting to assign " +
|
4797
4931
|
"{:a => 'a', :b => [{:c => 'c', :d => 'd'}, " +
|
4798
4932
|
"{:e => 'e', :f => 'f'}]}" do
|
4799
|
-
|
4800
|
-
|
4801
|
-
|
4802
|
-
|
4933
|
+
(lambda do
|
4934
|
+
@uri.query_values = {
|
4935
|
+
:a => "a", :b => [{:c => "c", :d => "d"}, {:e => "e", :f => "f"}]
|
4936
|
+
}
|
4937
|
+
end).should raise_error(TypeError)
|
4803
4938
|
end
|
4804
4939
|
|
4805
|
-
it "should
|
4940
|
+
it "should raise an error attempting to assign " +
|
4806
4941
|
"{:a => 'a', :b => [{:c => true, :d => 'd'}, " +
|
4807
4942
|
"{:e => 'e', :f => 'f'}]}" do
|
4808
|
-
|
4809
|
-
|
4810
|
-
|
4811
|
-
|
4943
|
+
(lambda do
|
4944
|
+
@uri.query_values = {
|
4945
|
+
:a => 'a', :b => [{:c => true, :d => 'd'}, {:e => 'e', :f => 'f'}]
|
4946
|
+
}
|
4947
|
+
end).should raise_error(TypeError)
|
4812
4948
|
end
|
4813
4949
|
|
4814
|
-
it "should
|
4950
|
+
it "should raise an error attempting to assign " +
|
4815
4951
|
"{:a => 'a', :b => {:c => true, :d => 'd'}}" do
|
4816
|
-
|
4817
|
-
|
4818
|
-
|
4819
|
-
|
4952
|
+
(lambda do
|
4953
|
+
@uri.query_values = {
|
4954
|
+
:a => 'a', :b => {:c => true, :d => 'd'}
|
4955
|
+
}
|
4956
|
+
end).should raise_error(TypeError)
|
4820
4957
|
end
|
4821
4958
|
|
4822
|
-
it "should
|
4959
|
+
it "should raise an error attempting to assign " +
|
4823
4960
|
"{:a => 'a', :b => {:c => true, :d => 'd'}}" do
|
4824
|
-
|
4825
|
-
|
4826
|
-
|
4827
|
-
|
4961
|
+
(lambda do
|
4962
|
+
@uri.query_values = {
|
4963
|
+
:a => 'a', :b => {:c => true, :d => 'd'}
|
4964
|
+
}
|
4965
|
+
end).should raise_error(TypeError)
|
4828
4966
|
end
|
4829
4967
|
|
4830
4968
|
it "should correctly assign {:a => 1, :b => 1.5}" do
|
@@ -4832,18 +4970,16 @@ describe Addressable::URI, "when assigning query values" do
|
|
4832
4970
|
@uri.query.should == "a=1&b=1.5"
|
4833
4971
|
end
|
4834
4972
|
|
4835
|
-
it "should
|
4973
|
+
it "should raise an error attempting to assign " +
|
4836
4974
|
"{:z => 1, :f => [2, {999.1 => [3,'4']}, ['h', 'i']], " +
|
4837
4975
|
":a => {:b => ['c', 'd'], :e => true, :y => 0.5}}" do
|
4838
|
-
|
4839
|
-
|
4840
|
-
|
4841
|
-
|
4842
|
-
|
4843
|
-
|
4844
|
-
|
4845
|
-
"f[1][999.1][0]=3&f[1][999.1][1]=4&f[2][0]=h&f[2][1]=i&z=1"
|
4846
|
-
)
|
4976
|
+
(lambda do
|
4977
|
+
@uri.query_values = {
|
4978
|
+
:z => 1,
|
4979
|
+
:f => [ 2, {999.1 => [3,'4']}, ['h', 'i'] ],
|
4980
|
+
:a => { :b => ['c', 'd'], :e => true, :y => 0.5 }
|
4981
|
+
}
|
4982
|
+
end).should raise_error(TypeError)
|
4847
4983
|
end
|
4848
4984
|
|
4849
4985
|
it "should correctly assign {}" do
|
@@ -4872,7 +5008,7 @@ describe Addressable::URI, "when assigning query values" do
|
|
4872
5008
|
query_string = (('a'..'z').to_a.reverse.map { |e| "#{e}=#{e}" }).join("&")
|
4873
5009
|
@uri.query = query_string
|
4874
5010
|
original_uri = @uri.to_s
|
4875
|
-
@uri.query_values = @uri.query_values(
|
5011
|
+
@uri.query_values = @uri.query_values(Array)
|
4876
5012
|
@uri.to_s.should == original_uri
|
4877
5013
|
end
|
4878
5014
|
end
|