honkster-addressable 2.1.2 → 2.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +82 -59
- data/LICENSE +1 -1
- data/README +12 -2
- data/Rakefile +0 -32
- data/lib/addressable/template.rb +1 -1
- data/lib/addressable/uri.rb +330 -105
- data/lib/addressable/version.rb +3 -3
- data/spec/addressable/uri_spec.rb +726 -21
- data/tasks/gem.rake +16 -0
- data/tasks/rdoc.rake +0 -3
- data/tasks/rubyforge.rake +2 -2
- data/tasks/yard.rake +26 -0
- data/website/index.html +110 -0
- metadata +70 -25
- data/spec/addressable/spec_helper.rb +0 -5
- data/spec/data/rfc3986.txt +0 -3419
data/lib/addressable/version.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding:utf-8
|
2
2
|
#--
|
3
|
-
# Addressable, Copyright (c) 2006-
|
3
|
+
# Addressable, Copyright (c) 2006-2010 Bob Aman
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining
|
6
6
|
# a copy of this software and associated documentation files (the
|
@@ -27,8 +27,8 @@ if !defined?(Addressable::VERSION)
|
|
27
27
|
module Addressable
|
28
28
|
module VERSION #:nodoc:
|
29
29
|
MAJOR = 2
|
30
|
-
MINOR =
|
31
|
-
TINY =
|
30
|
+
MINOR = 2
|
31
|
+
TINY = 5
|
32
32
|
|
33
33
|
STRING = [MAJOR, MINOR, TINY].join('.')
|
34
34
|
end
|
@@ -164,6 +164,10 @@ describe Addressable::URI, "when created from nil components" do
|
|
164
164
|
@uri = Addressable::URI.new
|
165
165
|
end
|
166
166
|
|
167
|
+
it "should have a nil site value" do
|
168
|
+
@uri.site.should == nil
|
169
|
+
end
|
170
|
+
|
167
171
|
it "should have an empty path" do
|
168
172
|
@uri.path.should == ""
|
169
173
|
end
|
@@ -172,9 +176,16 @@ describe Addressable::URI, "when created from nil components" do
|
|
172
176
|
@uri.to_s.should == ""
|
173
177
|
end
|
174
178
|
|
175
|
-
it "should
|
176
|
-
|
177
|
-
|
179
|
+
it "should raise an error if the scheme is set to whitespace" do
|
180
|
+
(lambda do
|
181
|
+
@uri.scheme = "\t \n"
|
182
|
+
end).should raise_error(Addressable::URI::InvalidURIError)
|
183
|
+
end
|
184
|
+
|
185
|
+
it "should raise an error if the scheme is set to all digits" do
|
186
|
+
(lambda do
|
187
|
+
@uri.scheme = "123"
|
188
|
+
end).should raise_error(Addressable::URI::InvalidURIError)
|
178
189
|
end
|
179
190
|
|
180
191
|
it "should raise an error if set into an invalid state" do
|
@@ -211,6 +222,10 @@ describe Addressable::URI, "when created from string components" do
|
|
211
222
|
)
|
212
223
|
end
|
213
224
|
|
225
|
+
it "should have a site value of 'http://example.com'" do
|
226
|
+
@uri.site.should == "http://example.com"
|
227
|
+
end
|
228
|
+
|
214
229
|
it "should be equal to the equivalent parsed URI" do
|
215
230
|
@uri.should == Addressable::URI.parse("http://example.com")
|
216
231
|
end
|
@@ -253,6 +268,14 @@ describe Addressable::URI, "when created with an authority and no port" do
|
|
253
268
|
@uri.port.should == nil
|
254
269
|
@uri.inferred_port.should == nil
|
255
270
|
end
|
271
|
+
|
272
|
+
it "should have a site value of '//user@example.com'" do
|
273
|
+
@uri.site.should == "//user@example.com"
|
274
|
+
end
|
275
|
+
|
276
|
+
it "should have a 'null' origin" do
|
277
|
+
@uri.origin.should == 'null'
|
278
|
+
end
|
256
279
|
end
|
257
280
|
|
258
281
|
describe Addressable::URI, "when created with both a userinfo and a user" do
|
@@ -265,35 +288,65 @@ end
|
|
265
288
|
|
266
289
|
describe Addressable::URI, "when created with a path that hasn't been " +
|
267
290
|
"prefixed with a '/' but a host specified" do
|
268
|
-
|
269
|
-
Addressable::URI.new(
|
291
|
+
before do
|
292
|
+
@uri = Addressable::URI.new(
|
270
293
|
:scheme => "http", :host => "example.com", :path => "path"
|
271
|
-
)
|
294
|
+
)
|
295
|
+
end
|
296
|
+
|
297
|
+
it "should prefix a '/' to the path" do
|
298
|
+
@uri.should == Addressable::URI.parse("http://example.com/path")
|
299
|
+
end
|
300
|
+
|
301
|
+
it "should have a site value of 'http://example.com'" do
|
302
|
+
@uri.site.should == "http://example.com"
|
303
|
+
end
|
304
|
+
|
305
|
+
it "should have an origin of 'http://example.com" do
|
306
|
+
@uri.origin.should == 'http://example.com'
|
272
307
|
end
|
273
308
|
end
|
274
309
|
|
275
310
|
describe Addressable::URI, "when created with a path that hasn't been " +
|
276
311
|
"prefixed with a '/' but no host specified" do
|
277
|
-
|
278
|
-
Addressable::URI.new(
|
312
|
+
before do
|
313
|
+
@uri = Addressable::URI.new(
|
279
314
|
:scheme => "http", :path => "path"
|
280
|
-
)
|
315
|
+
)
|
316
|
+
end
|
317
|
+
|
318
|
+
it "should not prefix a '/' to the path" do
|
319
|
+
@uri.should == Addressable::URI.parse("http:path")
|
320
|
+
end
|
321
|
+
|
322
|
+
it "should have a site value of 'http:'" do
|
323
|
+
@uri.site.should == "http:"
|
324
|
+
end
|
325
|
+
|
326
|
+
it "should have a 'null' origin" do
|
327
|
+
@uri.origin.should == 'null'
|
281
328
|
end
|
282
329
|
end
|
283
330
|
|
284
331
|
describe Addressable::URI, "when parsed from an Addressable::URI object" do
|
285
|
-
it "should
|
286
|
-
|
287
|
-
(
|
288
|
-
|
289
|
-
|
332
|
+
it "should not have unexpected side-effects" do
|
333
|
+
original_uri = Addressable::URI.parse("http://example.com/")
|
334
|
+
new_uri = Addressable::URI.parse(original_uri)
|
335
|
+
new_uri.host = 'www.example.com'
|
336
|
+
new_uri.host.should == 'www.example.com'
|
337
|
+
new_uri.to_s.should == 'http://www.example.com/'
|
338
|
+
original_uri.host.should == 'example.com'
|
339
|
+
original_uri.to_s.should == 'http://example.com/'
|
290
340
|
end
|
291
341
|
|
292
|
-
it "should
|
293
|
-
|
294
|
-
(
|
295
|
-
|
296
|
-
|
342
|
+
it "should not have unexpected side-effects" do
|
343
|
+
original_uri = Addressable::URI.parse("http://example.com/")
|
344
|
+
new_uri = Addressable::URI.heuristic_parse(original_uri)
|
345
|
+
new_uri.host = 'www.example.com'
|
346
|
+
new_uri.host.should == 'www.example.com'
|
347
|
+
new_uri.to_s.should == 'http://www.example.com/'
|
348
|
+
original_uri.host.should == 'example.com'
|
349
|
+
original_uri.to_s.should == 'http://example.com/'
|
297
350
|
end
|
298
351
|
end
|
299
352
|
|
@@ -335,6 +388,10 @@ describe Addressable::URI, "when parsed from ''" do
|
|
335
388
|
it "should be considered to be in normal form" do
|
336
389
|
@uri.normalize.should be_eql(@uri)
|
337
390
|
end
|
391
|
+
|
392
|
+
it "should have a 'null' origin" do
|
393
|
+
@uri.origin.should == 'null'
|
394
|
+
end
|
338
395
|
end
|
339
396
|
|
340
397
|
# Section 1.1.2 of RFC 3986
|
@@ -367,6 +424,10 @@ describe Addressable::URI, "when parsed from " +
|
|
367
424
|
it "should be considered to be in normal form" do
|
368
425
|
@uri.normalize.should be_eql(@uri)
|
369
426
|
end
|
427
|
+
|
428
|
+
it "should have an origin of 'ftp://ftp.is.co.za'" do
|
429
|
+
@uri.origin.should == 'ftp://ftp.is.co.za'
|
430
|
+
end
|
370
431
|
end
|
371
432
|
|
372
433
|
# Section 1.1.2 of RFC 3986
|
@@ -409,6 +470,10 @@ describe Addressable::URI, "when parsed from " +
|
|
409
470
|
@uri.omit!(:scheme)
|
410
471
|
@uri.to_s.should == "//www.ietf.org/rfc/rfc2396.txt"
|
411
472
|
end
|
473
|
+
|
474
|
+
it "should have an origin of 'http://www.ietf.org'" do
|
475
|
+
@uri.origin.should == 'http://www.ietf.org'
|
476
|
+
end
|
412
477
|
end
|
413
478
|
|
414
479
|
# Section 1.1.2 of RFC 3986
|
@@ -467,6 +532,10 @@ describe Addressable::URI, "when parsed from " +
|
|
467
532
|
@uri.omit(:authority, :path)
|
468
533
|
end).should raise_error(Addressable::URI::InvalidURIError)
|
469
534
|
end
|
535
|
+
|
536
|
+
it "should have an origin of 'ldap://[2001:db8::7]'" do
|
537
|
+
@uri.origin.should == 'ldap://[2001:db8::7]'
|
538
|
+
end
|
470
539
|
end
|
471
540
|
|
472
541
|
# Section 1.1.2 of RFC 3986
|
@@ -495,6 +564,10 @@ describe Addressable::URI, "when parsed from " +
|
|
495
564
|
it "should be considered to be in normal form" do
|
496
565
|
@uri.normalize.should be_eql(@uri)
|
497
566
|
end
|
567
|
+
|
568
|
+
it "should have a 'null' origin" do
|
569
|
+
@uri.origin.should == 'null'
|
570
|
+
end
|
498
571
|
end
|
499
572
|
|
500
573
|
# Section 1.1.2 of RFC 3986
|
@@ -523,6 +596,10 @@ describe Addressable::URI, "when parsed from " +
|
|
523
596
|
it "should be considered to be in normal form" do
|
524
597
|
@uri.normalize.should be_eql(@uri)
|
525
598
|
end
|
599
|
+
|
600
|
+
it "should have a 'null' origin" do
|
601
|
+
@uri.origin.should == 'null'
|
602
|
+
end
|
526
603
|
end
|
527
604
|
|
528
605
|
# Section 1.1.2 of RFC 3986
|
@@ -551,6 +628,10 @@ describe Addressable::URI, "when parsed from " +
|
|
551
628
|
it "should be considered to be in normal form" do
|
552
629
|
@uri.normalize.should be_eql(@uri)
|
553
630
|
end
|
631
|
+
|
632
|
+
it "should have a 'null' origin" do
|
633
|
+
@uri.origin.should == 'null'
|
634
|
+
end
|
554
635
|
end
|
555
636
|
|
556
637
|
# Section 1.1.2 of RFC 3986
|
@@ -587,6 +668,10 @@ describe Addressable::URI, "when parsed from " +
|
|
587
668
|
it "should be considered to be in normal form" do
|
588
669
|
@uri.normalize.should be_eql(@uri)
|
589
670
|
end
|
671
|
+
|
672
|
+
it "should have an origin of 'telnet://192.0.2.16:80'" do
|
673
|
+
@uri.origin.should == 'telnet://192.0.2.16:80'
|
674
|
+
end
|
590
675
|
end
|
591
676
|
|
592
677
|
# Section 1.1.2 of RFC 3986
|
@@ -617,6 +702,10 @@ describe Addressable::URI, "when parsed from " +
|
|
617
702
|
it "should be considered to be in normal form" do
|
618
703
|
@uri.normalize.should be_eql(@uri)
|
619
704
|
end
|
705
|
+
|
706
|
+
it "should have a 'null' origin" do
|
707
|
+
@uri.origin.should == 'null'
|
708
|
+
end
|
620
709
|
end
|
621
710
|
|
622
711
|
describe Addressable::URI, "when parsed from " +
|
@@ -734,6 +823,27 @@ describe Addressable::URI, "when parsed from " +
|
|
734
823
|
@uri.join!(@uri).to_s.should == "http://example.com"
|
735
824
|
end
|
736
825
|
|
826
|
+
it "should be equivalent to http://EXAMPLE.com" do
|
827
|
+
@uri.should == Addressable::URI.parse("http://EXAMPLE.com")
|
828
|
+
end
|
829
|
+
|
830
|
+
it "should be equivalent to http://EXAMPLE.com:80/" do
|
831
|
+
@uri.should == Addressable::URI.parse("http://EXAMPLE.com:80/")
|
832
|
+
end
|
833
|
+
|
834
|
+
it "should have the same hash as http://example.com" do
|
835
|
+
@uri.hash.should == Addressable::URI.parse("http://example.com").hash
|
836
|
+
end
|
837
|
+
|
838
|
+
it "should have the same hash as http://EXAMPLE.com after assignment" do
|
839
|
+
@uri.host = "EXAMPLE.com"
|
840
|
+
@uri.hash.should == Addressable::URI.parse("http://EXAMPLE.com").hash
|
841
|
+
end
|
842
|
+
|
843
|
+
it "should have a different hash from http://EXAMPLE.com" do
|
844
|
+
@uri.hash.should_not == Addressable::URI.parse("http://EXAMPLE.com").hash
|
845
|
+
end
|
846
|
+
|
737
847
|
# Section 6.2.3 of RFC 3986
|
738
848
|
it "should be equivalent to http://example.com/" do
|
739
849
|
@uri.should == Addressable::URI.parse("http://example.com/")
|
@@ -871,6 +981,10 @@ describe Addressable::URI, "when parsed from " +
|
|
871
981
|
it "should be identical to its duplicate" do
|
872
982
|
@uri.should == @uri.dup
|
873
983
|
end
|
984
|
+
|
985
|
+
it "should have an origin of 'http://example.com'" do
|
986
|
+
@uri.origin.should == 'http://example.com'
|
987
|
+
end
|
874
988
|
end
|
875
989
|
|
876
990
|
# Section 5.1.2 of RFC 2616
|
@@ -898,6 +1012,12 @@ describe Addressable::URI, "when parsed from " +
|
|
898
1012
|
@uri.query.should == "x=y"
|
899
1013
|
end
|
900
1014
|
|
1015
|
+
it "should raise an error if the site value is set to something bogus" do
|
1016
|
+
(lambda do
|
1017
|
+
@uri.site = 42
|
1018
|
+
end).should raise_error(TypeError)
|
1019
|
+
end
|
1020
|
+
|
901
1021
|
it "should raise an error if the request URI is set to something bogus" do
|
902
1022
|
(lambda do
|
903
1023
|
@uri.request_uri = 42
|
@@ -916,6 +1036,10 @@ describe Addressable::URI, "when parsed from " +
|
|
916
1036
|
:fragment => nil
|
917
1037
|
}
|
918
1038
|
end
|
1039
|
+
|
1040
|
+
it "should have an origin of 'http://www.w3.org'" do
|
1041
|
+
@uri.origin.should == 'http://www.w3.org'
|
1042
|
+
end
|
919
1043
|
end
|
920
1044
|
|
921
1045
|
describe Addressable::URI, "when parsed from " +
|
@@ -995,6 +1119,46 @@ describe Addressable::URI, "when parsed from " +
|
|
995
1119
|
it "should have the same hash as an equal URI" do
|
996
1120
|
@uri.hash.should == Addressable::URI.parse("http://example.com/").hash
|
997
1121
|
end
|
1122
|
+
|
1123
|
+
it "should be equivalent to http://EXAMPLE.com" do
|
1124
|
+
@uri.should == Addressable::URI.parse("http://EXAMPLE.com")
|
1125
|
+
end
|
1126
|
+
|
1127
|
+
it "should be equivalent to http://EXAMPLE.com:80/" do
|
1128
|
+
@uri.should == Addressable::URI.parse("http://EXAMPLE.com:80/")
|
1129
|
+
end
|
1130
|
+
|
1131
|
+
it "should have the same hash as http://example.com/" do
|
1132
|
+
@uri.hash.should == Addressable::URI.parse("http://example.com/").hash
|
1133
|
+
end
|
1134
|
+
|
1135
|
+
it "should have the same hash as http://example.com after assignment" do
|
1136
|
+
@uri.path = ""
|
1137
|
+
@uri.hash.should == Addressable::URI.parse("http://example.com").hash
|
1138
|
+
end
|
1139
|
+
|
1140
|
+
it "should have the same hash as http://example.com/? after assignment" do
|
1141
|
+
@uri.query = ""
|
1142
|
+
@uri.hash.should == Addressable::URI.parse("http://example.com/?").hash
|
1143
|
+
end
|
1144
|
+
|
1145
|
+
it "should have the same hash as http://example.com/? after assignment" do
|
1146
|
+
@uri.query_values = {}
|
1147
|
+
@uri.hash.should == Addressable::URI.parse("http://example.com/?").hash
|
1148
|
+
end
|
1149
|
+
|
1150
|
+
it "should have the same hash as http://example.com/# after assignment" do
|
1151
|
+
@uri.fragment = ""
|
1152
|
+
@uri.hash.should == Addressable::URI.parse("http://example.com/#").hash
|
1153
|
+
end
|
1154
|
+
|
1155
|
+
it "should have a different hash from http://example.com" do
|
1156
|
+
@uri.hash.should_not == Addressable::URI.parse("http://example.com").hash
|
1157
|
+
end
|
1158
|
+
|
1159
|
+
it "should have an origin of 'http://example.com'" do
|
1160
|
+
@uri.origin.should == 'http://example.com'
|
1161
|
+
end
|
998
1162
|
end
|
999
1163
|
|
1000
1164
|
describe Addressable::URI, "when parsed from " +
|
@@ -1023,6 +1187,10 @@ describe Addressable::URI, "when parsed from " +
|
|
1023
1187
|
it "should be identical to its duplicate" do
|
1024
1188
|
@uri.should == @uri.dup
|
1025
1189
|
end
|
1190
|
+
|
1191
|
+
it "should have an origin of 'http://example.com'" do
|
1192
|
+
@uri.origin.should == 'http://example.com'
|
1193
|
+
end
|
1026
1194
|
end
|
1027
1195
|
|
1028
1196
|
describe Addressable::URI, "when parsed from " +
|
@@ -1042,6 +1210,10 @@ describe Addressable::URI, "when parsed from " +
|
|
1042
1210
|
it "should be identical to its duplicate" do
|
1043
1211
|
@uri.should == @uri.dup
|
1044
1212
|
end
|
1213
|
+
|
1214
|
+
it "should have an origin of 'http://example.com'" do
|
1215
|
+
@uri.origin.should == 'http://example.com'
|
1216
|
+
end
|
1045
1217
|
end
|
1046
1218
|
|
1047
1219
|
describe Addressable::URI, "when parsed from " +
|
@@ -1070,6 +1242,10 @@ describe Addressable::URI, "when parsed from " +
|
|
1070
1242
|
it "should be identical to its duplicate" do
|
1071
1243
|
@uri.should == @uri.dup
|
1072
1244
|
end
|
1245
|
+
|
1246
|
+
it "should have an origin of 'http://example.com'" do
|
1247
|
+
@uri.origin.should == 'http://example.com'
|
1248
|
+
end
|
1073
1249
|
end
|
1074
1250
|
|
1075
1251
|
describe Addressable::URI, "when parsed from " +
|
@@ -1479,6 +1655,10 @@ describe Addressable::URI, "when parsed from " +
|
|
1479
1655
|
it "should be identical to its duplicate" do
|
1480
1656
|
@uri.should == @uri.dup
|
1481
1657
|
end
|
1658
|
+
|
1659
|
+
it "should have an origin of 'http://example.com'" do
|
1660
|
+
@uri.origin.should == 'http://example.com'
|
1661
|
+
end
|
1482
1662
|
end
|
1483
1663
|
|
1484
1664
|
describe Addressable::URI, "when parsed from " +
|
@@ -1576,6 +1756,10 @@ describe Addressable::URI, "when parsed from " +
|
|
1576
1756
|
it "should be identical to its duplicate" do
|
1577
1757
|
@uri.should == @uri.dup
|
1578
1758
|
end
|
1759
|
+
|
1760
|
+
it "should have an origin of 'http://example.com:8080'" do
|
1761
|
+
@uri.origin.should == 'http://example.com:8080'
|
1762
|
+
end
|
1579
1763
|
end
|
1580
1764
|
|
1581
1765
|
describe Addressable::URI, "when parsed from " +
|
@@ -1595,6 +1779,48 @@ describe Addressable::URI, "when parsed from " +
|
|
1595
1779
|
it "should normalize to 'http://example.com/'" do
|
1596
1780
|
@uri.normalize.should === "http://example.com/"
|
1597
1781
|
end
|
1782
|
+
|
1783
|
+
it "should have an origin of 'http://example.com'" do
|
1784
|
+
@uri.origin.should == 'http://example.com'
|
1785
|
+
end
|
1786
|
+
end
|
1787
|
+
|
1788
|
+
describe Addressable::URI, "when parsed from " +
|
1789
|
+
"'http://example.com/..'" do
|
1790
|
+
before do
|
1791
|
+
@uri = Addressable::URI.parse("http://example.com/..")
|
1792
|
+
end
|
1793
|
+
|
1794
|
+
it "should have the correct port" do
|
1795
|
+
@uri.inferred_port.should == 80
|
1796
|
+
end
|
1797
|
+
|
1798
|
+
it "should not be considered to be in normal form" do
|
1799
|
+
@uri.normalize.should_not be_eql(@uri)
|
1800
|
+
end
|
1801
|
+
|
1802
|
+
it "should normalize to 'http://example.com/'" do
|
1803
|
+
@uri.normalize.should === "http://example.com/"
|
1804
|
+
end
|
1805
|
+
end
|
1806
|
+
|
1807
|
+
describe Addressable::URI, "when parsed from " +
|
1808
|
+
"'http://example.com/../..'" do
|
1809
|
+
before do
|
1810
|
+
@uri = Addressable::URI.parse("http://example.com/../..")
|
1811
|
+
end
|
1812
|
+
|
1813
|
+
it "should have the correct port" do
|
1814
|
+
@uri.inferred_port.should == 80
|
1815
|
+
end
|
1816
|
+
|
1817
|
+
it "should not be considered to be in normal form" do
|
1818
|
+
@uri.normalize.should_not be_eql(@uri)
|
1819
|
+
end
|
1820
|
+
|
1821
|
+
it "should normalize to 'http://example.com/'" do
|
1822
|
+
@uri.normalize.should === "http://example.com/"
|
1823
|
+
end
|
1598
1824
|
end
|
1599
1825
|
|
1600
1826
|
describe Addressable::URI, "when parsed from " +
|
@@ -2026,10 +2252,10 @@ describe Addressable::URI, "when parsed from " +
|
|
2026
2252
|
end
|
2027
2253
|
|
2028
2254
|
describe Addressable::URI, "when parsed from " +
|
2029
|
-
"'ssh+svn://developername@
|
2255
|
+
"'ssh+svn://developername@RUBYFORGE.ORG/var/svn/project'" do
|
2030
2256
|
before do
|
2031
2257
|
@uri = Addressable::URI.parse(
|
2032
|
-
"ssh+svn://developername@
|
2258
|
+
"ssh+svn://developername@RUBYFORGE.ORG/var/svn/project"
|
2033
2259
|
)
|
2034
2260
|
end
|
2035
2261
|
|
@@ -2041,6 +2267,10 @@ describe Addressable::URI, "when parsed from " +
|
|
2041
2267
|
@uri.normalized_scheme.should == "svn+ssh"
|
2042
2268
|
end
|
2043
2269
|
|
2270
|
+
it "should have a normalized site of 'svn+ssh'" do
|
2271
|
+
@uri.normalized_site.should == "svn+ssh://developername@rubyforge.org"
|
2272
|
+
end
|
2273
|
+
|
2044
2274
|
it "should not be considered to be ip-based" do
|
2045
2275
|
@uri.should_not be_ip_based
|
2046
2276
|
end
|
@@ -2116,6 +2346,10 @@ describe Addressable::URI, "when parsed from " +
|
|
2116
2346
|
it "should be considered to be in normal form" do
|
2117
2347
|
@uri.normalize.should be_eql(@uri)
|
2118
2348
|
end
|
2349
|
+
|
2350
|
+
it "should have a 'null' origin" do
|
2351
|
+
@uri.origin.should == 'null'
|
2352
|
+
end
|
2119
2353
|
end
|
2120
2354
|
|
2121
2355
|
describe Addressable::URI, "when parsed from " +
|
@@ -2157,6 +2391,10 @@ describe Addressable::URI, "when parsed from " +
|
|
2157
2391
|
it "should be considered to be in normal form" do
|
2158
2392
|
@uri.normalize.should be_eql(@uri)
|
2159
2393
|
end
|
2394
|
+
|
2395
|
+
it "should have a 'null' origin" do
|
2396
|
+
@uri.origin.should == 'null'
|
2397
|
+
end
|
2160
2398
|
end
|
2161
2399
|
|
2162
2400
|
describe Addressable::URI, "when parsed from " +
|
@@ -2268,6 +2506,22 @@ describe Addressable::URI, "when parsed from " +
|
|
2268
2506
|
"bogus%21://user:pass@example.com/path/to/resource?query=x#fragment"
|
2269
2507
|
end
|
2270
2508
|
|
2509
|
+
it "should have the correct site segment after assignment" do
|
2510
|
+
@uri.site = "https://newuser:newpass@example.com:443"
|
2511
|
+
@uri.scheme.should == "https"
|
2512
|
+
@uri.authority.should == "newuser:newpass@example.com:443"
|
2513
|
+
@uri.user.should == "newuser"
|
2514
|
+
@uri.password.should == "newpass"
|
2515
|
+
@uri.userinfo.should == "newuser:newpass"
|
2516
|
+
@uri.normalized_userinfo.should == "newuser:newpass"
|
2517
|
+
@uri.host.should == "example.com"
|
2518
|
+
@uri.port.should == 443
|
2519
|
+
@uri.inferred_port.should == 443
|
2520
|
+
@uri.to_s.should ==
|
2521
|
+
"https://newuser:newpass@example.com:443" +
|
2522
|
+
"/path/to/resource?query=x#fragment"
|
2523
|
+
end
|
2524
|
+
|
2271
2525
|
it "should have the correct authority segment after assignment" do
|
2272
2526
|
@uri.authority = "newuser:newpass@example.com:80"
|
2273
2527
|
@uri.authority.should == "newuser:newpass@example.com:80"
|
@@ -2328,6 +2582,20 @@ describe Addressable::URI, "when parsed from " +
|
|
2328
2582
|
"http://user:pass@example.com/newpath/to/resource?query=x#fragment"
|
2329
2583
|
end
|
2330
2584
|
|
2585
|
+
it "should have the correct scheme and authority after nil assignment" do
|
2586
|
+
@uri.site = nil
|
2587
|
+
@uri.scheme.should == nil
|
2588
|
+
@uri.authority.should == nil
|
2589
|
+
@uri.to_s.should == "/path/to/resource?query=x#fragment"
|
2590
|
+
end
|
2591
|
+
|
2592
|
+
it "should have the correct scheme and authority after assignment" do
|
2593
|
+
@uri.site = "file://"
|
2594
|
+
@uri.scheme.should == "file"
|
2595
|
+
@uri.authority.should == ""
|
2596
|
+
@uri.to_s.should == "file:///path/to/resource?query=x#fragment"
|
2597
|
+
end
|
2598
|
+
|
2331
2599
|
it "should have the correct path after nil assignment" do
|
2332
2600
|
@uri.path = nil
|
2333
2601
|
@uri.path.should == ""
|
@@ -2416,12 +2684,14 @@ describe Addressable::URI, "when parsed from " +
|
|
2416
2684
|
it "should have the correct values after a merge" do
|
2417
2685
|
@uri.merge(:authority => "foo:bar@baz:42").to_s.should ==
|
2418
2686
|
"http://foo:bar@baz:42/path/to/resource?query=x#fragment"
|
2687
|
+
# Ensure the operation was not destructive
|
2419
2688
|
@uri.to_s.should ==
|
2420
2689
|
"http://user:pass@example.com/path/to/resource?query=x#fragment"
|
2421
2690
|
end
|
2422
2691
|
|
2423
2692
|
it "should have the correct values after a destructive merge" do
|
2424
2693
|
@uri.merge!(:authority => "foo:bar@baz:42")
|
2694
|
+
# Ensure the operation was destructive
|
2425
2695
|
@uri.to_s.should ==
|
2426
2696
|
"http://foo:bar@baz:42/path/to/resource?query=x#fragment"
|
2427
2697
|
end
|
@@ -2432,6 +2702,12 @@ describe Addressable::URI, "when parsed from " +
|
|
2432
2702
|
end).should raise_error(Addressable::URI::InvalidURIError)
|
2433
2703
|
end
|
2434
2704
|
|
2705
|
+
it "should fail to merge with bogus values" do
|
2706
|
+
(lambda do
|
2707
|
+
@uri.merge(:authority => "bar@baz:bogus")
|
2708
|
+
end).should raise_error(Addressable::URI::InvalidURIError)
|
2709
|
+
end
|
2710
|
+
|
2435
2711
|
it "should fail to merge with bogus parameters" do
|
2436
2712
|
(lambda do
|
2437
2713
|
@uri.merge(42)
|
@@ -2459,6 +2735,70 @@ describe Addressable::URI, "when parsed from " +
|
|
2459
2735
|
it "should be identical to its duplicate" do
|
2460
2736
|
@uri.should == @uri.dup
|
2461
2737
|
end
|
2738
|
+
|
2739
|
+
it "should have an origin of 'http://example.com'" do
|
2740
|
+
@uri.origin.should == 'http://example.com'
|
2741
|
+
end
|
2742
|
+
end
|
2743
|
+
|
2744
|
+
describe Addressable::URI, "when parsed from " +
|
2745
|
+
"'http://example.com/?q&&x=b'" do
|
2746
|
+
before do
|
2747
|
+
@uri = Addressable::URI.parse("http://example.com/?q&&x=b")
|
2748
|
+
end
|
2749
|
+
|
2750
|
+
it "should have a query of 'q&&x=b'" do
|
2751
|
+
@uri.query.should == "q&&x=b"
|
2752
|
+
end
|
2753
|
+
|
2754
|
+
it "should have query_values of {'q' => true, 'x' => 'b'}" do
|
2755
|
+
@uri.query_values.should == {'q' => true, 'x' => 'b'}
|
2756
|
+
end
|
2757
|
+
end
|
2758
|
+
|
2759
|
+
describe Addressable::URI, "when parsed from " +
|
2760
|
+
"'http://example.com/?q=a+b'" do
|
2761
|
+
before do
|
2762
|
+
@uri = Addressable::URI.parse("http://example.com/?q=a+b")
|
2763
|
+
end
|
2764
|
+
|
2765
|
+
it "should have a query of 'q=a+b'" do
|
2766
|
+
@uri.query.should == "q=a+b"
|
2767
|
+
end
|
2768
|
+
|
2769
|
+
it "should have query_values of {'q' => 'a b'}" do
|
2770
|
+
@uri.query_values.should == {'q' => 'a b'}
|
2771
|
+
end
|
2772
|
+
end
|
2773
|
+
|
2774
|
+
describe Addressable::URI, "when parsed from " +
|
2775
|
+
"'http://example.com/?q=a%2bb'" do
|
2776
|
+
before do
|
2777
|
+
@uri = Addressable::URI.parse("http://example.com/?q=a%2bb")
|
2778
|
+
end
|
2779
|
+
|
2780
|
+
it "should have a query of 'q=a+b'" do
|
2781
|
+
@uri.query.should == "q=a%2bb"
|
2782
|
+
end
|
2783
|
+
|
2784
|
+
it "should have query_values of {'q' => 'a+b'}" do
|
2785
|
+
@uri.query_values.should == {'q' => 'a+b'}
|
2786
|
+
end
|
2787
|
+
end
|
2788
|
+
|
2789
|
+
describe Addressable::URI, "when parsed from " +
|
2790
|
+
"'http://example.com/?q='" do
|
2791
|
+
before do
|
2792
|
+
@uri = Addressable::URI.parse("http://example.com/?q=")
|
2793
|
+
end
|
2794
|
+
|
2795
|
+
it "should have a query of 'q='" do
|
2796
|
+
@uri.query.should == "q="
|
2797
|
+
end
|
2798
|
+
|
2799
|
+
it "should have query_values of {'q' => ''}" do
|
2800
|
+
@uri.query_values.should == {'q' => ''}
|
2801
|
+
end
|
2462
2802
|
end
|
2463
2803
|
|
2464
2804
|
describe Addressable::URI, "when parsed from " +
|
@@ -2734,6 +3074,14 @@ describe Addressable::URI, "when parsed from " +
|
|
2734
3074
|
@uri.host.should == nil
|
2735
3075
|
end
|
2736
3076
|
|
3077
|
+
it "should have a site of nil" do
|
3078
|
+
@uri.site.should == nil
|
3079
|
+
end
|
3080
|
+
|
3081
|
+
it "should have a normalized_site of nil" do
|
3082
|
+
@uri.normalized_site.should == nil
|
3083
|
+
end
|
3084
|
+
|
2737
3085
|
it "should have a path of ''" do
|
2738
3086
|
@uri.path.should == ""
|
2739
3087
|
end
|
@@ -2773,6 +3121,10 @@ describe Addressable::URI, "when parsed from " +
|
|
2773
3121
|
@uri.route_from("http://example.com/")
|
2774
3122
|
end).should raise_error(ArgumentError, /\/\/example.com\//)
|
2775
3123
|
end
|
3124
|
+
|
3125
|
+
it "should have a 'null' origin" do
|
3126
|
+
@uri.origin.should == 'null'
|
3127
|
+
end
|
2776
3128
|
end
|
2777
3129
|
|
2778
3130
|
describe Addressable::URI, "when parsed from " +
|
@@ -2804,6 +3156,10 @@ describe Addressable::URI, "when parsed from " +
|
|
2804
3156
|
@uri.normalize.to_s.should == "http://example.com/"
|
2805
3157
|
@uri.normalize!.to_s.should == "http://example.com/"
|
2806
3158
|
end
|
3159
|
+
|
3160
|
+
it "should have a 'null' origin" do
|
3161
|
+
@uri.origin.should == 'null'
|
3162
|
+
end
|
2807
3163
|
end
|
2808
3164
|
|
2809
3165
|
describe Addressable::URI, "when parsed from " +
|
@@ -2817,6 +3173,10 @@ describe Addressable::URI, "when parsed from " +
|
|
2817
3173
|
@uri.should ==
|
2818
3174
|
Addressable::URI.parse("eXAMPLE://a/./b/../b/%63/%7bfoo%7d")
|
2819
3175
|
end
|
3176
|
+
|
3177
|
+
it "should have an origin of 'example://a'" do
|
3178
|
+
@uri.origin.should == 'example://a'
|
3179
|
+
end
|
2820
3180
|
end
|
2821
3181
|
|
2822
3182
|
describe Addressable::URI, "when parsed from " +
|
@@ -2871,6 +3231,10 @@ describe Addressable::URI, "when parsed from " +
|
|
2871
3231
|
it "should have no scheme" do
|
2872
3232
|
@uri.scheme.should == nil
|
2873
3233
|
end
|
3234
|
+
|
3235
|
+
it "should have a 'null' origin" do
|
3236
|
+
@uri.origin.should == 'null'
|
3237
|
+
end
|
2874
3238
|
end
|
2875
3239
|
|
2876
3240
|
describe Addressable::URI, "when parsed from " +
|
@@ -2886,6 +3250,10 @@ describe Addressable::URI, "when parsed from " +
|
|
2886
3250
|
it "should have a scheme of 'this'" do
|
2887
3251
|
@uri.scheme.should == "this"
|
2888
3252
|
end
|
3253
|
+
|
3254
|
+
it "should have a 'null' origin" do
|
3255
|
+
@uri.origin.should == 'null'
|
3256
|
+
end
|
2889
3257
|
end
|
2890
3258
|
|
2891
3259
|
describe Addressable::URI, "when parsed from '?'" do
|
@@ -2905,6 +3273,10 @@ describe Addressable::URI, "when parsed from '?'" do
|
|
2905
3273
|
it "should have the correct flat notation query values" do
|
2906
3274
|
@uri.query_values(:notation => :flat).should == {}
|
2907
3275
|
end
|
3276
|
+
|
3277
|
+
it "should have a 'null' origin" do
|
3278
|
+
@uri.origin.should == 'null'
|
3279
|
+
end
|
2908
3280
|
end
|
2909
3281
|
|
2910
3282
|
describe Addressable::URI, "when parsed from '?one=1&two=2&three=3'" do
|
@@ -2921,6 +3293,32 @@ describe Addressable::URI, "when parsed from '?one=1&two=2&three=3'" do
|
|
2921
3293
|
@uri.query_values(:notation => :bogus)
|
2922
3294
|
end).should raise_error(ArgumentError)
|
2923
3295
|
end
|
3296
|
+
|
3297
|
+
it "should have the correct flat array notation query values" do
|
3298
|
+
@uri.query_values(:notation => :flat_array).should == [
|
3299
|
+
["one", "1"], ["two", "2"], ["three", "3"]
|
3300
|
+
]
|
3301
|
+
end
|
3302
|
+
|
3303
|
+
it "should have a 'null' origin" do
|
3304
|
+
@uri.origin.should == 'null'
|
3305
|
+
end
|
3306
|
+
end
|
3307
|
+
|
3308
|
+
describe Addressable::URI, "when parsed from '?one=1=uno&two=2=dos'" do
|
3309
|
+
before do
|
3310
|
+
@uri = Addressable::URI.parse("?one=1=uno&two=2=dos")
|
3311
|
+
end
|
3312
|
+
|
3313
|
+
it "should have the correct query values" do
|
3314
|
+
@uri.query_values.should == {"one" => "1=uno", "two" => "2=dos"}
|
3315
|
+
end
|
3316
|
+
|
3317
|
+
it "should have the correct flat array notation query values" do
|
3318
|
+
@uri.query_values(:notation => :flat_array).should == [
|
3319
|
+
["one", "1=uno"], ["two", "2=dos"]
|
3320
|
+
]
|
3321
|
+
end
|
2924
3322
|
end
|
2925
3323
|
|
2926
3324
|
describe Addressable::URI, "when parsed from '?one[two][three]=four'" do
|
@@ -2937,6 +3335,12 @@ describe Addressable::URI, "when parsed from '?one[two][three]=four'" do
|
|
2937
3335
|
"one[two][three]" => "four"
|
2938
3336
|
}
|
2939
3337
|
end
|
3338
|
+
|
3339
|
+
it "should have the correct flat array notation query values" do
|
3340
|
+
@uri.query_values(:notation => :flat_array).should == [
|
3341
|
+
["one[two][three]", "four"]
|
3342
|
+
]
|
3343
|
+
end
|
2940
3344
|
end
|
2941
3345
|
|
2942
3346
|
describe Addressable::URI, "when parsed from '?one.two.three=four'" do
|
@@ -2955,6 +3359,12 @@ describe Addressable::URI, "when parsed from '?one.two.three=four'" do
|
|
2955
3359
|
"one.two.three" => "four"
|
2956
3360
|
}
|
2957
3361
|
end
|
3362
|
+
|
3363
|
+
it "should have the correct flat array notation query values" do
|
3364
|
+
@uri.query_values(:notation => :flat_array).should == [
|
3365
|
+
["one.two.three", "four"]
|
3366
|
+
]
|
3367
|
+
end
|
2958
3368
|
end
|
2959
3369
|
|
2960
3370
|
describe Addressable::URI, "when parsed from " +
|
@@ -2975,6 +3385,12 @@ describe Addressable::URI, "when parsed from " +
|
|
2975
3385
|
"one[two][five]" => "six"
|
2976
3386
|
}
|
2977
3387
|
end
|
3388
|
+
|
3389
|
+
it "should have the correct flat array notation query values" do
|
3390
|
+
@uri.query_values(:notation => :flat_array).should == [
|
3391
|
+
["one[two][three]", "four"], ["one[two][five]", "six"]
|
3392
|
+
]
|
3393
|
+
end
|
2978
3394
|
end
|
2979
3395
|
|
2980
3396
|
describe Addressable::URI, "when parsed from " +
|
@@ -2995,6 +3411,26 @@ describe Addressable::URI, "when parsed from " +
|
|
2995
3411
|
"one.two.five" => "six"
|
2996
3412
|
}
|
2997
3413
|
end
|
3414
|
+
|
3415
|
+
it "should have the correct flat array notation query values" do
|
3416
|
+
@uri.query_values(:notation => :flat_array).should == [
|
3417
|
+
["one.two.three", "four"], ["one.two.five", "six"]
|
3418
|
+
]
|
3419
|
+
end
|
3420
|
+
end
|
3421
|
+
|
3422
|
+
describe Addressable::URI, "when parsed from " +
|
3423
|
+
"'?one=two&one=three'" do
|
3424
|
+
before do
|
3425
|
+
@uri = Addressable::URI.parse(
|
3426
|
+
"?one=two&one=three"
|
3427
|
+
)
|
3428
|
+
end
|
3429
|
+
|
3430
|
+
it "should have correct flat_array notation query values" do
|
3431
|
+
@uri.query_values(:notation => :flat_array).should ==
|
3432
|
+
[['one', 'two'], ['one', 'three']]
|
3433
|
+
end
|
2998
3434
|
end
|
2999
3435
|
|
3000
3436
|
describe Addressable::URI, "when parsed from " +
|
@@ -3016,6 +3452,13 @@ describe Addressable::URI, "when parsed from " +
|
|
3016
3452
|
@uri.query_values(:notation => :flat)
|
3017
3453
|
end).should raise_error(ArgumentError)
|
3018
3454
|
end
|
3455
|
+
|
3456
|
+
it "should not raise an error if a key is " +
|
3457
|
+
"repeated in the flat array notation" do
|
3458
|
+
(lambda do
|
3459
|
+
@uri.query_values(:notation => :flat_array)
|
3460
|
+
end).should_not raise_error
|
3461
|
+
end
|
3019
3462
|
end
|
3020
3463
|
|
3021
3464
|
describe Addressable::URI, "when parsed from " +
|
@@ -3033,6 +3476,36 @@ describe Addressable::URI, "when parsed from " +
|
|
3033
3476
|
end
|
3034
3477
|
end
|
3035
3478
|
|
3479
|
+
describe Addressable::URI, "when parsed from " +
|
3480
|
+
"'?one[two][three][1]=four&one[two][three][0]=five'" do
|
3481
|
+
before do
|
3482
|
+
@uri = Addressable::URI.parse(
|
3483
|
+
"?one[two][three][1]=four&one[two][three][0]=five"
|
3484
|
+
)
|
3485
|
+
end
|
3486
|
+
|
3487
|
+
it "should have the correct subscript notation query values" do
|
3488
|
+
@uri.query_values(:notation => :subscript).should == {
|
3489
|
+
"one" => {"two" => {"three" => ["five", "four"]}}
|
3490
|
+
}
|
3491
|
+
end
|
3492
|
+
end
|
3493
|
+
|
3494
|
+
describe Addressable::URI, "when parsed from " +
|
3495
|
+
"'?one[two][three][2]=four&one[two][three][1]=five'" do
|
3496
|
+
before do
|
3497
|
+
@uri = Addressable::URI.parse(
|
3498
|
+
"?one[two][three][2]=four&one[two][three][1]=five"
|
3499
|
+
)
|
3500
|
+
end
|
3501
|
+
|
3502
|
+
it "should have the correct subscript notation query values" do
|
3503
|
+
@uri.query_values(:notation => :subscript).should == {
|
3504
|
+
"one" => {"two" => {"three" => ["five", "four"]}}
|
3505
|
+
}
|
3506
|
+
end
|
3507
|
+
end
|
3508
|
+
|
3036
3509
|
describe Addressable::URI, "when parsed from " +
|
3037
3510
|
"'http://www.詹姆斯.com/'" do
|
3038
3511
|
before do
|
@@ -3048,6 +3521,10 @@ describe Addressable::URI, "when parsed from " +
|
|
3048
3521
|
Addressable::URI.normalized_encode(@uri.to_s).should ==
|
3049
3522
|
"http://www.詹姆斯.com/"
|
3050
3523
|
end
|
3524
|
+
|
3525
|
+
it "should have an origin of 'http://www.xn--8ws00zhy3a.com'" do
|
3526
|
+
@uri.origin.should == 'http://www.xn--8ws00zhy3a.com'
|
3527
|
+
end
|
3051
3528
|
end
|
3052
3529
|
|
3053
3530
|
describe Addressable::URI, "when parsed from " +
|
@@ -3067,6 +3544,10 @@ describe Addressable::URI, "when parsed from " +
|
|
3067
3544
|
Addressable::URI.normalized_encode(@uri.to_s).should ==
|
3068
3545
|
"http://www.詹姆斯.com/%20some%20spaces%20/"
|
3069
3546
|
end
|
3547
|
+
|
3548
|
+
it "should have an origin of 'http://www.xn--8ws00zhy3a.com'" do
|
3549
|
+
@uri.origin.should == 'http://www.xn--8ws00zhy3a.com'
|
3550
|
+
end
|
3070
3551
|
end
|
3071
3552
|
|
3072
3553
|
describe Addressable::URI, "when parsed from " +
|
@@ -3086,6 +3567,10 @@ describe Addressable::URI, "when parsed from " +
|
|
3086
3567
|
display_string.encoding.to_s.should == Encoding::UTF_8.to_s
|
3087
3568
|
end
|
3088
3569
|
end
|
3570
|
+
|
3571
|
+
it "should have an origin of 'http://www.xn--8ws00zhy3a.com'" do
|
3572
|
+
@uri.origin.should == 'http://www.xn--8ws00zhy3a.com'
|
3573
|
+
end
|
3089
3574
|
end
|
3090
3575
|
|
3091
3576
|
describe Addressable::URI, "when parsed from " +
|
@@ -3123,6 +3608,13 @@ describe Addressable::URI, "when parsed from a percent-encoded IRI" do
|
|
3123
3608
|
"http://www.xn--n8jaaaaai5bhf7as8fsfk3jnknefdde3f" +
|
3124
3609
|
"g11amb5gzdb4wi9bya3kc6lra.w3.mag.keio.ac.jp/"
|
3125
3610
|
end
|
3611
|
+
|
3612
|
+
it "should have the correct origin" do
|
3613
|
+
@uri.origin.should == (
|
3614
|
+
"http://www.xn--n8jaaaaai5bhf7as8fsfk3jnknefdde3f" +
|
3615
|
+
"g11amb5gzdb4wi9bya3kc6lra.w3.mag.keio.ac.jp"
|
3616
|
+
)
|
3617
|
+
end
|
3126
3618
|
end
|
3127
3619
|
|
3128
3620
|
describe Addressable::URI, "with a base uri of 'http://a/b/c/d;p?q'" do
|
@@ -3455,6 +3947,11 @@ describe Addressable::URI, "when given a UNIX root directory" do
|
|
3455
3947
|
@uri = Addressable::URI.convert_path(@path)
|
3456
3948
|
@uri.to_str.should == "file:///"
|
3457
3949
|
end
|
3950
|
+
|
3951
|
+
it "should have an origin of 'file://'" do
|
3952
|
+
@uri = Addressable::URI.convert_path(@path)
|
3953
|
+
@uri.origin.should == 'file://'
|
3954
|
+
end
|
3458
3955
|
end
|
3459
3956
|
|
3460
3957
|
describe Addressable::URI, "when given a Windows root directory" do
|
@@ -3466,6 +3963,11 @@ describe Addressable::URI, "when given a Windows root directory" do
|
|
3466
3963
|
@uri = Addressable::URI.convert_path(@path)
|
3467
3964
|
@uri.to_str.should == "file:///c:/"
|
3468
3965
|
end
|
3966
|
+
|
3967
|
+
it "should have an origin of 'file://'" do
|
3968
|
+
@uri = Addressable::URI.convert_path(@path)
|
3969
|
+
@uri.origin.should == 'file://'
|
3970
|
+
end
|
3469
3971
|
end
|
3470
3972
|
|
3471
3973
|
describe Addressable::URI, "when given the path '/home/user/'" do
|
@@ -3478,6 +3980,11 @@ describe Addressable::URI, "when given the path '/home/user/'" do
|
|
3478
3980
|
@uri = Addressable::URI.convert_path(@path)
|
3479
3981
|
@uri.to_str.should == "file:///home/user/"
|
3480
3982
|
end
|
3983
|
+
|
3984
|
+
it "should have an origin of 'file://'" do
|
3985
|
+
@uri = Addressable::URI.convert_path(@path)
|
3986
|
+
@uri.origin.should == 'file://'
|
3987
|
+
end
|
3481
3988
|
end
|
3482
3989
|
|
3483
3990
|
describe Addressable::URI, "when given the path " +
|
@@ -3491,6 +3998,11 @@ describe Addressable::URI, "when given the path " +
|
|
3491
3998
|
@uri = Addressable::URI.convert_path(@path)
|
3492
3999
|
@uri.to_str.should == "file:///c:/windows/My%20Documents%20100%20/foo.txt"
|
3493
4000
|
end
|
4001
|
+
|
4002
|
+
it "should have an origin of 'file://'" do
|
4003
|
+
@uri = Addressable::URI.convert_path(@path)
|
4004
|
+
@uri.origin.should == 'file://'
|
4005
|
+
end
|
3494
4006
|
end
|
3495
4007
|
|
3496
4008
|
describe Addressable::URI, "when given the path " +
|
@@ -3504,6 +4016,11 @@ describe Addressable::URI, "when given the path " +
|
|
3504
4016
|
@uri = Addressable::URI.convert_path(@path)
|
3505
4017
|
@uri.to_str.should == "file:///c:/windows/My%20Documents%20100%20/foo.txt"
|
3506
4018
|
end
|
4019
|
+
|
4020
|
+
it "should have an origin of 'file://'" do
|
4021
|
+
@uri = Addressable::URI.convert_path(@path)
|
4022
|
+
@uri.origin.should == 'file://'
|
4023
|
+
end
|
3507
4024
|
end
|
3508
4025
|
|
3509
4026
|
describe Addressable::URI, "when given the path " +
|
@@ -3517,6 +4034,11 @@ describe Addressable::URI, "when given the path " +
|
|
3517
4034
|
@uri = Addressable::URI.convert_path(@path)
|
3518
4035
|
@uri.to_str.should == "file:///c:/windows/My%20Documents%20100%20/foo.txt"
|
3519
4036
|
end
|
4037
|
+
|
4038
|
+
it "should have an origin of 'file://'" do
|
4039
|
+
@uri = Addressable::URI.convert_path(@path)
|
4040
|
+
@uri.origin.should == 'file://'
|
4041
|
+
end
|
3520
4042
|
end
|
3521
4043
|
|
3522
4044
|
describe Addressable::URI, "when given the path " +
|
@@ -3530,6 +4052,11 @@ describe Addressable::URI, "when given the path " +
|
|
3530
4052
|
@uri = Addressable::URI.convert_path(@path)
|
3531
4053
|
@uri.to_str.should == "file:///c:/windows/My%20Documents%20100%20/foo.txt"
|
3532
4054
|
end
|
4055
|
+
|
4056
|
+
it "should have an origin of 'file://'" do
|
4057
|
+
@uri = Addressable::URI.convert_path(@path)
|
4058
|
+
@uri.origin.should == 'file://'
|
4059
|
+
end
|
3533
4060
|
end
|
3534
4061
|
|
3535
4062
|
describe Addressable::URI, "when given the path " +
|
@@ -3543,6 +4070,11 @@ describe Addressable::URI, "when given the path " +
|
|
3543
4070
|
@uri = Addressable::URI.convert_path(@path)
|
3544
4071
|
@uri.to_str.should == "file:///c:/windows/My%20Documents%20100%20/foo.txt"
|
3545
4072
|
end
|
4073
|
+
|
4074
|
+
it "should have an origin of 'file://'" do
|
4075
|
+
@uri = Addressable::URI.convert_path(@path)
|
4076
|
+
@uri.origin.should == 'file://'
|
4077
|
+
end
|
3546
4078
|
end
|
3547
4079
|
|
3548
4080
|
describe Addressable::URI, "when given an http protocol URI" do
|
@@ -3588,6 +4120,95 @@ describe Addressable::URI, "when parsing a non-String object" do
|
|
3588
4120
|
end
|
3589
4121
|
end
|
3590
4122
|
|
4123
|
+
describe Addressable::URI, "when form encoding a hash" do
|
4124
|
+
it "should result in correct percent encoded sequence" do
|
4125
|
+
Addressable::URI.form_encode(
|
4126
|
+
{"&one" => "/1", "=two" => "?2", ":three" => "#3"}
|
4127
|
+
).should == "%26one=%2F1&%3Dtwo=%3F2&%3Athree=%233"
|
4128
|
+
end
|
4129
|
+
|
4130
|
+
it "should result in correct percent encoded sequence" do
|
4131
|
+
Addressable::URI.form_encode(
|
4132
|
+
{"q" => "one two three"}
|
4133
|
+
).should == "q=one+two+three"
|
4134
|
+
end
|
4135
|
+
|
4136
|
+
it "should result in correct percent encoded sequence" do
|
4137
|
+
Addressable::URI.form_encode(
|
4138
|
+
{"key" => nil}
|
4139
|
+
).should == "key="
|
4140
|
+
end
|
4141
|
+
|
4142
|
+
it "should result in correctly encoded newlines" do
|
4143
|
+
Addressable::URI.form_encode(
|
4144
|
+
{"text" => "one\ntwo\rthree\r\nfour\n\r"}
|
4145
|
+
).should == "text=one%0D%0Atwo%0D%0Athree%0D%0Afour%0D%0A%0D%0A"
|
4146
|
+
end
|
4147
|
+
|
4148
|
+
it "should result in a sorted percent encoded sequence" do
|
4149
|
+
Addressable::URI.form_encode(
|
4150
|
+
[["a", "1"], ["dup", "3"], ["dup", "2"]], true
|
4151
|
+
).should == "a=1&dup=2&dup=3"
|
4152
|
+
end
|
4153
|
+
end
|
4154
|
+
|
4155
|
+
describe Addressable::URI, "when form encoding a non-Array object" do
|
4156
|
+
it "should raise a TypeError for objects than cannot be converted" do
|
4157
|
+
(lambda do
|
4158
|
+
Addressable::URI.form_encode(42)
|
4159
|
+
end).should raise_error(TypeError, "Can't convert Fixnum into Array.")
|
4160
|
+
end
|
4161
|
+
end
|
4162
|
+
|
4163
|
+
describe Addressable::URI, "when form unencoding a string" do
|
4164
|
+
it "should result in correct values" do
|
4165
|
+
Addressable::URI.form_unencode(
|
4166
|
+
"%26one=%2F1&%3Dtwo=%3F2&%3Athree=%233"
|
4167
|
+
).should == [["&one", "/1"], ["=two", "?2"], [":three", "#3"]]
|
4168
|
+
end
|
4169
|
+
|
4170
|
+
it "should result in correct values" do
|
4171
|
+
Addressable::URI.form_unencode(
|
4172
|
+
"q=one+two+three"
|
4173
|
+
).should == [["q", "one two three"]]
|
4174
|
+
end
|
4175
|
+
|
4176
|
+
it "should result in correct values" do
|
4177
|
+
Addressable::URI.form_unencode(
|
4178
|
+
"text=one%0D%0Atwo%0D%0Athree%0D%0Afour%0D%0A%0D%0A"
|
4179
|
+
).should == [["text", "one\ntwo\nthree\nfour\n\n"]]
|
4180
|
+
end
|
4181
|
+
|
4182
|
+
it "should result in correct values" do
|
4183
|
+
Addressable::URI.form_unencode(
|
4184
|
+
"a=1&dup=2&dup=3"
|
4185
|
+
).should == [["a", "1"], ["dup", "2"], ["dup", "3"]]
|
4186
|
+
end
|
4187
|
+
|
4188
|
+
it "should result in correct values" do
|
4189
|
+
Addressable::URI.form_unencode(
|
4190
|
+
"key"
|
4191
|
+
).should == [["key", nil]]
|
4192
|
+
end
|
4193
|
+
|
4194
|
+
it "should result in correct values" do
|
4195
|
+
Addressable::URI.form_unencode("GivenName=Ren%C3%A9").should ==
|
4196
|
+
[["GivenName", "René"]]
|
4197
|
+
end
|
4198
|
+
end
|
4199
|
+
|
4200
|
+
describe Addressable::URI, "when form unencoding a non-String object" do
|
4201
|
+
it "should correctly parse anything with a 'to_str' method" do
|
4202
|
+
Addressable::URI.form_unencode(SuperString.new(42))
|
4203
|
+
end
|
4204
|
+
|
4205
|
+
it "should raise a TypeError for objects than cannot be converted" do
|
4206
|
+
(lambda do
|
4207
|
+
Addressable::URI.form_unencode(42)
|
4208
|
+
end).should raise_error(TypeError, "Can't convert Fixnum into String.")
|
4209
|
+
end
|
4210
|
+
end
|
4211
|
+
|
3591
4212
|
describe Addressable::URI, "when normalizing a non-String object" do
|
3592
4213
|
it "should correctly parse anything with a 'to_str' method" do
|
3593
4214
|
Addressable::URI.normalize_component(SuperString.new(42))
|
@@ -3665,6 +4286,13 @@ describe Addressable::URI, "when encoding a multibyte string" do
|
|
3665
4286
|
end
|
3666
4287
|
end
|
3667
4288
|
|
4289
|
+
describe Addressable::URI, "when form encoding a multibyte string" do
|
4290
|
+
it "should result in correct percent encoded sequence" do
|
4291
|
+
Addressable::URI.form_encode({"GivenName" => "René"}).should ==
|
4292
|
+
"GivenName=Ren%C3%A9"
|
4293
|
+
end
|
4294
|
+
end
|
4295
|
+
|
3668
4296
|
describe Addressable::URI, "when encoding a string with ASCII chars 0-15" do
|
3669
4297
|
it "should result in correct percent encoded sequence" do
|
3670
4298
|
Addressable::URI.encode_component("one\ntwo").should == "one%0Atwo"
|
@@ -3937,4 +4565,81 @@ describe Addressable::URI, "when assigning query values" do
|
|
3937
4565
|
}
|
3938
4566
|
@uri.query.should == "a=a&b[c]&b[d]=d"
|
3939
4567
|
end
|
4568
|
+
|
4569
|
+
it "should correctly assign {}" do
|
4570
|
+
@uri.query_values = {}
|
4571
|
+
@uri.query.should == ''
|
4572
|
+
end
|
4573
|
+
|
4574
|
+
it "should correctly assign nil" do
|
4575
|
+
@uri.query_values = nil
|
4576
|
+
@uri.query.should == nil
|
4577
|
+
end
|
4578
|
+
|
4579
|
+
it "should correctly sort {'ab' => 'c', :ab => 'a', :a => 'x'}" do
|
4580
|
+
@uri.query_values = {'ab' => 'c', :ab => 'a', :a => 'x'}
|
4581
|
+
@uri.query.should == "a=x&ab=a&ab=c"
|
4582
|
+
end
|
4583
|
+
|
4584
|
+
it "should correctly assign " +
|
4585
|
+
"[['b', 'c'], ['b', 'a'], ['a', 'a']]" do
|
4586
|
+
# Order can be guaranteed in this format, so preserve it.
|
4587
|
+
@uri.query_values = [['b', 'c'], ['b', 'a'], ['a', 'a']]
|
4588
|
+
@uri.query.should == "b=c&b=a&a=a"
|
4589
|
+
end
|
4590
|
+
|
4591
|
+
it "should preserve query string order" do
|
4592
|
+
query_string = (('a'..'z').to_a.shuffle.map { |e| "#{e}=#{e}" }).join("&")
|
4593
|
+
@uri.query = query_string
|
4594
|
+
original_uri = @uri.to_s
|
4595
|
+
@uri.query_values = @uri.query_values(:notation => :flat_array)
|
4596
|
+
@uri.to_s.should == original_uri
|
4597
|
+
end
|
4598
|
+
end
|
4599
|
+
|
4600
|
+
describe Addressable::URI, "when assigning path values" do
|
4601
|
+
before do
|
4602
|
+
@uri = Addressable::URI.new
|
4603
|
+
end
|
4604
|
+
|
4605
|
+
it "should correctly assign paths containing colons" do
|
4606
|
+
@uri.path = "acct:bob@sporkmonger.com"
|
4607
|
+
Addressable::URI.parse(@uri.normalize.to_str).path.should == @uri.path
|
4608
|
+
@uri.normalize.to_str.should == "acct%2Fbob@sporkmonger.com"
|
4609
|
+
end
|
4610
|
+
|
4611
|
+
it "should correctly assign paths containing colons" do
|
4612
|
+
@uri.path = "/acct:bob@sporkmonger.com"
|
4613
|
+
@uri.authority = "example.com"
|
4614
|
+
@uri.normalize.to_str.should == "//example.com/acct:bob@sporkmonger.com"
|
4615
|
+
end
|
4616
|
+
|
4617
|
+
it "should correctly assign paths containing colons" do
|
4618
|
+
@uri.path = "acct:bob@sporkmonger.com"
|
4619
|
+
@uri.scheme = "something"
|
4620
|
+
@uri.normalize.to_str.should == "something:acct:bob@sporkmonger.com"
|
4621
|
+
end
|
4622
|
+
|
4623
|
+
it "should not allow relative paths to be assigned on absolute URIs" do
|
4624
|
+
(lambda do
|
4625
|
+
@uri.scheme = "http"
|
4626
|
+
@uri.host = "example.com"
|
4627
|
+
@uri.path = "acct:bob@sporkmonger.com"
|
4628
|
+
end).should raise_error(Addressable::URI::InvalidURIError)
|
4629
|
+
end
|
4630
|
+
|
4631
|
+
it "should not allow relative paths to be assigned on absolute URIs" do
|
4632
|
+
(lambda do
|
4633
|
+
@uri.path = "acct:bob@sporkmonger.com"
|
4634
|
+
@uri.scheme = "http"
|
4635
|
+
@uri.host = "example.com"
|
4636
|
+
end).should raise_error(Addressable::URI::InvalidURIError)
|
4637
|
+
end
|
4638
|
+
|
4639
|
+
it "should not allow relative paths to be assigned on absolute URIs" do
|
4640
|
+
(lambda do
|
4641
|
+
@uri.path = "uuid:0b3ecf60-3f93-11df-a9c3-001f5bfffe12"
|
4642
|
+
@uri.scheme = "urn"
|
4643
|
+
end).should_not raise_error(Addressable::URI::InvalidURIError)
|
4644
|
+
end
|
3940
4645
|
end
|