addressable 2.0.2 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- # coding:utf-8
1
+ # encoding: utf-8
2
2
  #--
3
3
  # Addressable, Copyright (c) 2006-2007 Bob Aman
4
4
  #
@@ -30,48 +30,37 @@ require "addressable/uri"
30
30
  if !"".respond_to?("force_encoding")
31
31
  class String
32
32
  def force_encoding(encoding)
33
- # Do nothing, just make sure this gets called.
33
+ @encoding = encoding
34
34
  end
35
- end
36
-
37
- class Encoding
38
- UTF_8 = Encoding.new
39
- ASCII_8BIT = Encoding.new
40
- end
41
- end
42
35
 
43
- class ExampleProcessor
44
- def self.validate(name, value)
45
- return !!(value =~ /^[\w ]+$/) if name == "query"
46
- return true
36
+ def encoding
37
+ @encoding ||= Encoding::ASCII_8BIT
38
+ end
47
39
  end
48
40
 
49
- def self.transform(name, value)
50
- return value.gsub(/ /, "+") if name == "query"
51
- return value
52
- end
41
+ class Encoding
42
+ def initialize(name)
43
+ @name = name
44
+ end
53
45
 
54
- def self.restore(name, value)
55
- return value.gsub(/\+/, " ") if name == "query"
56
- return value.tr("A-Za-z", "N-ZA-Mn-za-m") if name == "rot13"
57
- return value
58
- end
46
+ def to_s
47
+ return @name
48
+ end
59
49
 
60
- def self.match(name)
61
- return ".*?" if name == "first"
62
- return ".*"
50
+ UTF_8 = Encoding.new("UTF-8")
51
+ ASCII_8BIT = Encoding.new("US-ASCII")
63
52
  end
64
53
  end
65
54
 
66
- class SlashlessProcessor
67
- def self.match(name)
68
- return "[^/\\n]*"
69
- end
70
- end
55
+ module URI
56
+ class HTTP
57
+ def initialize(uri)
58
+ @uri = uri
59
+ end
71
60
 
72
- class NoOpProcessor
73
- def self.transform(name, value)
74
- value
61
+ def to_s
62
+ return @uri.to_s
63
+ end
75
64
  end
76
65
  end
77
66
 
@@ -104,6 +93,37 @@ describe Addressable::URI, "when created from nil components" do
104
93
  it "should be an empty uri" do
105
94
  @uri.to_s.should == ""
106
95
  end
96
+
97
+ it "should still be an empty uri if the scheme is set to whitespace" do
98
+ @uri.scheme = "\t \n"
99
+ @uri.to_s.should == ""
100
+ end
101
+
102
+ it "should raise an error if set into an invalid state" do
103
+ (lambda do
104
+ @uri.user = "user"
105
+ end).should raise_error(Addressable::URI::InvalidURIError)
106
+ end
107
+
108
+ it "should raise an error if set into an invalid state" do
109
+ (lambda do
110
+ @uri.password = "pass"
111
+ end).should raise_error(Addressable::URI::InvalidURIError)
112
+ end
113
+
114
+ it "should raise an error if set into an invalid state" do
115
+ (lambda do
116
+ @uri.scheme = "http"
117
+ @uri.fragment = "fragment"
118
+ end).should raise_error(Addressable::URI::InvalidURIError)
119
+ end
120
+
121
+ it "should raise an error if set into an invalid state" do
122
+ (lambda do
123
+ @uri.fragment = "fragment"
124
+ @uri.scheme = "http"
125
+ end).should raise_error(Addressable::URI::InvalidURIError)
126
+ end
107
127
  end
108
128
 
109
129
  describe Addressable::URI, "when created from string components" do
@@ -139,7 +159,9 @@ end
139
159
  describe Addressable::URI, "when created with both an authority and a user" do
140
160
  it "should raise an error" do
141
161
  (lambda do
142
- Addressable::URI.new(:user => "user", :authority => "user@example.com:80")
162
+ Addressable::URI.new(
163
+ :user => "user", :authority => "user@example.com:80"
164
+ )
143
165
  end).should raise_error(ArgumentError)
144
166
  end
145
167
  end
@@ -181,8 +203,60 @@ describe Addressable::URI, "when created with a path that hasn't been " +
181
203
  end
182
204
  end
183
205
 
206
+ describe Addressable::URI, "when parsed from an Addressable::URI object" do
207
+ it "should return the object" do
208
+ uri = Addressable::URI.parse("http://example.com/")
209
+ (lambda do
210
+ Addressable::URI.parse(uri).object_id.should == uri.object_id
211
+ end).should_not raise_error
212
+ end
213
+
214
+ it "should return the object" do
215
+ uri = Addressable::URI.parse("http://example.com/")
216
+ (lambda do
217
+ Addressable::URI.heuristic_parse(uri).object_id.should == uri.object_id
218
+ end).should_not raise_error
219
+ end
220
+ end
221
+
222
+ describe Addressable::URI, "when parsed from something that looks " +
223
+ "like a URI object" do
224
+ it "should parse without error" do
225
+ uri = Addressable::URI.parse(URI::HTTP.new("http://example.com/"))
226
+ (lambda do
227
+ Addressable::URI.parse(uri)
228
+ end).should_not raise_error
229
+ end
230
+ end
231
+
232
+ describe Addressable::URI, "when parsed from ''" do
233
+ before do
234
+ @uri = Addressable::URI.parse("")
235
+ end
236
+
237
+ it "should have no scheme" do
238
+ @uri.scheme.should == nil
239
+ end
240
+
241
+ it "should not be considered to be ip-based" do
242
+ @uri.should_not be_ip_based
243
+ end
244
+
245
+ it "should have a path of ''" do
246
+ @uri.path.should == ""
247
+ end
248
+
249
+ it "should be considered relative" do
250
+ @uri.should be_relative
251
+ end
252
+
253
+ it "should be considered to be in normal form" do
254
+ @uri.normalize.should be_eql(@uri)
255
+ end
256
+ end
257
+
184
258
  # Section 1.1.2 of RFC 3986
185
- describe Addressable::URI, " when parsed from " +
259
+ describe Addressable::URI, "when parsed from " +
186
260
  "'ftp://ftp.is.co.za/rfc/rfc1808.txt'" do
187
261
  before do
188
262
  @uri = Addressable::URI.parse("ftp://ftp.is.co.za/rfc/rfc1808.txt")
@@ -210,7 +284,7 @@ describe Addressable::URI, " when parsed from " +
210
284
  end
211
285
 
212
286
  # Section 1.1.2 of RFC 3986
213
- describe Addressable::URI, " when parsed from " +
287
+ describe Addressable::URI, "when parsed from " +
214
288
  "'http://www.ietf.org/rfc/rfc2396.txt'" do
215
289
  before do
216
290
  @uri = Addressable::URI.parse("http://www.ietf.org/rfc/rfc2396.txt")
@@ -287,10 +361,16 @@ describe Addressable::URI, "when parsed from " +
287
361
  @uri.omit!(:scheme, :authority)
288
362
  @uri.to_s.should == "/c=GB?objectClass?one"
289
363
  end
364
+
365
+ it "should raise an error if omission would create an invalid URI" do
366
+ (lambda do
367
+ @uri.omit(:authority, :path)
368
+ end).should raise_error(Addressable::URI::InvalidURIError)
369
+ end
290
370
  end
291
371
 
292
372
  # Section 1.1.2 of RFC 3986
293
- describe Addressable::URI, " when parsed from " +
373
+ describe Addressable::URI, "when parsed from " +
294
374
  "'mailto:John.Doe@example.com'" do
295
375
  before do
296
376
  @uri = Addressable::URI.parse("mailto:John.Doe@example.com")
@@ -314,7 +394,7 @@ describe Addressable::URI, " when parsed from " +
314
394
  end
315
395
 
316
396
  # Section 1.1.2 of RFC 3986
317
- describe Addressable::URI, " when parsed from " +
397
+ describe Addressable::URI, "when parsed from " +
318
398
  "'news:comp.infosystems.www.servers.unix'" do
319
399
  before do
320
400
  @uri = Addressable::URI.parse("news:comp.infosystems.www.servers.unix")
@@ -362,7 +442,7 @@ describe Addressable::URI, "when parsed from " +
362
442
  end
363
443
 
364
444
  # Section 1.1.2 of RFC 3986
365
- describe Addressable::URI, " when parsed from " +
445
+ describe Addressable::URI, "when parsed from " +
366
446
  "'telnet://192.0.2.16:80/'" do
367
447
  before do
368
448
  @uri = Addressable::URI.parse("telnet://192.0.2.16:80/")
@@ -394,7 +474,7 @@ describe Addressable::URI, " when parsed from " +
394
474
  end
395
475
 
396
476
  # Section 1.1.2 of RFC 3986
397
- describe Addressable::URI, " when parsed from " +
477
+ describe Addressable::URI, "when parsed from " +
398
478
  "'urn:oasis:names:specification:docbook:dtd:xml:4.1.2'" do
399
479
  before do
400
480
  @uri = Addressable::URI.parse(
@@ -419,7 +499,7 @@ describe Addressable::URI, " when parsed from " +
419
499
  end
420
500
  end
421
501
 
422
- describe Addressable::URI, " when parsed from " +
502
+ describe Addressable::URI, "when parsed from " +
423
503
  "'http://example.com'" do
424
504
  before do
425
505
  @uri = Addressable::URI.parse("http://example.com")
@@ -611,6 +691,7 @@ describe Addressable::URI, " when parsed from " +
611
691
  @uri.normalized_password.should == "secret%40123%21"
612
692
  @uri.user.should == ""
613
693
  @uri.normalize.to_s.should == "http://:secret%40123%21@example.com/"
694
+ @uri.omit(:password).to_s.should == "http://example.com"
614
695
  end
615
696
 
616
697
  it "should have the correct user/pass after repeated assignment" do
@@ -668,7 +749,7 @@ describe Addressable::URI, " when parsed from " +
668
749
  end
669
750
  end
670
751
 
671
- describe Addressable::URI, " when parsed from " +
752
+ describe Addressable::URI, "when parsed from " +
672
753
  "'http://example.com/'" do
673
754
  before do
674
755
  @uri = Addressable::URI.parse("http://example.com/")
@@ -738,12 +819,12 @@ describe Addressable::URI, " when parsed from " +
738
819
  @uri.hash.should_not == @uri.to_s.hash
739
820
  end
740
821
 
741
- it "should have the same hash as an equivalent URI" do
742
- @uri.hash.should == Addressable::URI.parse("http://example.com:80/").hash
822
+ it "should have the same hash as an equal URI" do
823
+ @uri.hash.should == Addressable::URI.parse("http://example.com/").hash
743
824
  end
744
825
  end
745
826
 
746
- describe Addressable::URI, " when parsed from " +
827
+ describe Addressable::URI, "when parsed from " +
747
828
  "'http://@example.com/'" do
748
829
  before do
749
830
  @uri = Addressable::URI.parse("http://@example.com/")
@@ -771,7 +852,7 @@ describe Addressable::URI, " when parsed from " +
771
852
  end
772
853
  end
773
854
 
774
- describe Addressable::URI, " when parsed from " +
855
+ describe Addressable::URI, "when parsed from " +
775
856
  "'http://example.com./'" do
776
857
  before do
777
858
  @uri = Addressable::URI.parse("http://example.com./")
@@ -790,7 +871,7 @@ describe Addressable::URI, " when parsed from " +
790
871
  end
791
872
  end
792
873
 
793
- describe Addressable::URI, " when parsed from " +
874
+ describe Addressable::URI, "when parsed from " +
794
875
  "'http://:@example.com/'" do
795
876
  before do
796
877
  @uri = Addressable::URI.parse("http://:@example.com/")
@@ -818,7 +899,7 @@ describe Addressable::URI, " when parsed from " +
818
899
  end
819
900
  end
820
901
 
821
- describe Addressable::URI, " when parsed from " +
902
+ describe Addressable::URI, "when parsed from " +
822
903
  "'http://example.com/~smith/'" do
823
904
  before do
824
905
  @uri = Addressable::URI.parse("http://example.com/~smith/")
@@ -839,7 +920,31 @@ describe Addressable::URI, " when parsed from " +
839
920
  end
840
921
  end
841
922
 
842
- describe Addressable::URI, " when parsed from " +
923
+ describe Addressable::URI, "when parsed from " +
924
+ "'http://example.com/%E8'" do
925
+ before do
926
+ @uri = Addressable::URI.parse("http://example.com/%E8")
927
+ end
928
+
929
+ it "should not raise an exception when normalized" do
930
+ (lambda do
931
+ @uri.normalize
932
+ end).should_not raise_error(ArgumentError)
933
+ end
934
+
935
+ it "should be considered to be in normal form" do
936
+ @uri.normalize.should be_eql(@uri)
937
+ end
938
+
939
+ it "should not change if encoded with the normalizing algorithm" do
940
+ Addressable::URI.normalized_encode(@uri).to_s.should ==
941
+ "http://example.com/%E8"
942
+ Addressable::URI.normalized_encode(@uri, Addressable::URI).to_s.should ===
943
+ "http://example.com/%E8"
944
+ end
945
+ end
946
+
947
+ describe Addressable::URI, "when parsed from " +
843
948
  "'http://example.com/%C3%87'" do
844
949
  before do
845
950
  @uri = Addressable::URI.parse("http://example.com/%C3%87")
@@ -884,7 +989,7 @@ describe Addressable::URI, " when parsed from " +
884
989
  end
885
990
  end
886
991
 
887
- describe Addressable::URI, " when parsed from " +
992
+ describe Addressable::URI, "when parsed from " +
888
993
  "'http://example.com/?q=string'" do
889
994
  before do
890
995
  @uri = Addressable::URI.parse("http://example.com/?q=string")
@@ -943,7 +1048,7 @@ describe Addressable::URI, " when parsed from " +
943
1048
  end
944
1049
  end
945
1050
 
946
- describe Addressable::URI, " when parsed from " +
1051
+ describe Addressable::URI, "when parsed from " +
947
1052
  "'http://example.com:80/'" do
948
1053
  before do
949
1054
  @uri = Addressable::URI.parse("http://example.com:80/")
@@ -1055,7 +1160,7 @@ describe Addressable::URI, " when parsed from " +
1055
1160
  end
1056
1161
  end
1057
1162
 
1058
- describe Addressable::URI, " when parsed from " +
1163
+ describe Addressable::URI, "when parsed from " +
1059
1164
  "'http://example.com:8080/'" do
1060
1165
  before do
1061
1166
  @uri = Addressable::URI.parse("http://example.com:8080/")
@@ -1152,7 +1257,7 @@ describe Addressable::URI, " when parsed from " +
1152
1257
  end
1153
1258
  end
1154
1259
 
1155
- describe Addressable::URI, " when parsed from " +
1260
+ describe Addressable::URI, "when parsed from " +
1156
1261
  "'http://example.com:%38%30/'" do
1157
1262
  before do
1158
1263
  @uri = Addressable::URI.parse("http://example.com:%38%30/")
@@ -1171,7 +1276,7 @@ describe Addressable::URI, " when parsed from " +
1171
1276
  end
1172
1277
  end
1173
1278
 
1174
- describe Addressable::URI, " when parsed from " +
1279
+ describe Addressable::URI, "when parsed from " +
1175
1280
  "'http://example.com/path/to/resource/'" do
1176
1281
  before do
1177
1282
  @uri = Addressable::URI.parse("http://example.com/path/to/resource/")
@@ -1409,7 +1514,7 @@ describe Addressable::URI, "when parsed from " +
1409
1514
  end
1410
1515
  end
1411
1516
 
1412
- describe Addressable::URI, " when parsed from " +
1517
+ describe Addressable::URI, "when parsed from " +
1413
1518
  "'http://example.com/file.txt'" do
1414
1519
  before do
1415
1520
  @uri = Addressable::URI.parse("http://example.com/file.txt")
@@ -1460,7 +1565,7 @@ describe Addressable::URI, " when parsed from " +
1460
1565
  end
1461
1566
  end
1462
1567
 
1463
- describe Addressable::URI, " when parsed from " +
1568
+ describe Addressable::URI, "when parsed from " +
1464
1569
  "'http://example.com/file.txt;parameter'" do
1465
1570
  before do
1466
1571
  @uri = Addressable::URI.parse("http://example.com/file.txt;parameter")
@@ -1511,7 +1616,7 @@ describe Addressable::URI, " when parsed from " +
1511
1616
  end
1512
1617
  end
1513
1618
 
1514
- describe Addressable::URI, " when parsed from " +
1619
+ describe Addressable::URI, "when parsed from " +
1515
1620
  "'http://example.com/file.txt;x=y'" do
1516
1621
  before do
1517
1622
  @uri = Addressable::URI.parse("http://example.com/file.txt;x=y")
@@ -1566,7 +1671,7 @@ describe Addressable::URI, " when parsed from " +
1566
1671
  end
1567
1672
  end
1568
1673
 
1569
- describe Addressable::URI, " when parsed from " +
1674
+ describe Addressable::URI, "when parsed from " +
1570
1675
  "'svn+ssh://developername@rubyforge.org/var/svn/project'" do
1571
1676
  before do
1572
1677
  @uri = Addressable::URI.parse(
@@ -1599,7 +1704,7 @@ describe Addressable::URI, " when parsed from " +
1599
1704
  end
1600
1705
  end
1601
1706
 
1602
- describe Addressable::URI, " when parsed from " +
1707
+ describe Addressable::URI, "when parsed from " +
1603
1708
  "'ssh+svn://developername@rubyforge.org/var/svn/project'" do
1604
1709
  before do
1605
1710
  @uri = Addressable::URI.parse(
@@ -1636,7 +1741,7 @@ describe Addressable::URI, " when parsed from " +
1636
1741
  end
1637
1742
  end
1638
1743
 
1639
- describe Addressable::URI, " when parsed from " +
1744
+ describe Addressable::URI, "when parsed from " +
1640
1745
  "'mailto:user@example.com'" do
1641
1746
  before do
1642
1747
  @uri = Addressable::URI.parse("mailto:user@example.com")
@@ -1663,7 +1768,7 @@ describe Addressable::URI, " when parsed from " +
1663
1768
  end
1664
1769
  end
1665
1770
 
1666
- describe Addressable::URI, " when parsed from " +
1771
+ describe Addressable::URI, "when parsed from " +
1667
1772
  "'tag:example.com,2006-08-18:/path/to/something'" do
1668
1773
  before do
1669
1774
  @uri = Addressable::URI.parse(
@@ -1692,7 +1797,7 @@ describe Addressable::URI, " when parsed from " +
1692
1797
  end
1693
1798
  end
1694
1799
 
1695
- describe Addressable::URI, " when parsed from " +
1800
+ describe Addressable::URI, "when parsed from " +
1696
1801
  "'http://example.com/x;y/'" do
1697
1802
  before do
1698
1803
  @uri = Addressable::URI.parse("http://example.com/x;y/")
@@ -1703,7 +1808,7 @@ describe Addressable::URI, " when parsed from " +
1703
1808
  end
1704
1809
  end
1705
1810
 
1706
- describe Addressable::URI, " when parsed from " +
1811
+ describe Addressable::URI, "when parsed from " +
1707
1812
  "'http://example.com/?x=1&y=2'" do
1708
1813
  before do
1709
1814
  @uri = Addressable::URI.parse("http://example.com/?x=1&y=2")
@@ -1714,7 +1819,7 @@ describe Addressable::URI, " when parsed from " +
1714
1819
  end
1715
1820
  end
1716
1821
 
1717
- describe Addressable::URI, " when parsed from " +
1822
+ describe Addressable::URI, "when parsed from " +
1718
1823
  "'view-source:http://example.com/'" do
1719
1824
  before do
1720
1825
  @uri = Addressable::URI.parse("view-source:http://example.com/")
@@ -1733,7 +1838,7 @@ describe Addressable::URI, " when parsed from " +
1733
1838
  end
1734
1839
  end
1735
1840
 
1736
- describe Addressable::URI, " when parsed from " +
1841
+ describe Addressable::URI, "when parsed from " +
1737
1842
  "'http://user:pass@example.com/path/to/resource?query=x#fragment'" do
1738
1843
  before do
1739
1844
  @uri = Addressable::URI.parse(
@@ -1831,11 +1936,15 @@ describe Addressable::URI, " when parsed from " +
1831
1936
  @uri.scheme.should == "ftp"
1832
1937
  @uri.to_s.should ==
1833
1938
  "ftp://user:pass@example.com/path/to/resource?query=x#fragment"
1939
+ @uri.to_str.should ==
1940
+ "ftp://user:pass@example.com/path/to/resource?query=x#fragment"
1834
1941
  @uri.scheme = "bogus!"
1835
1942
  @uri.scheme.should == "bogus!"
1836
1943
  @uri.normalized_scheme.should == "bogus%21"
1837
1944
  @uri.normalize.to_s.should ==
1838
1945
  "bogus%21://user:pass@example.com/path/to/resource?query=x#fragment"
1946
+ @uri.normalize.to_str.should ==
1947
+ "bogus%21://user:pass@example.com/path/to/resource?query=x#fragment"
1839
1948
  end
1840
1949
 
1841
1950
  it "should have the correct authority segment after assignment" do
@@ -1917,10 +2026,12 @@ describe Addressable::URI, " when parsed from " +
1917
2026
  end
1918
2027
 
1919
2028
  it "should have the correct query string after hash assignment" do
1920
- @uri.query_values = {"?uestion mark"=>"=sign", "hello"=>"günther"}
2029
+ @uri.query_values = {"?uestion mark"=>"=sign", "hello"=>"g\xC3\xBCnther"}
1921
2030
  @uri.query.split("&").should include("%3Fuestion%20mark=%3Dsign")
1922
2031
  @uri.query.split("&").should include("hello=g%C3%BCnther")
1923
- @uri.query_values.should == {"?uestion mark"=>"=sign", "hello"=>"günther"}
2032
+ @uri.query_values.should == {
2033
+ "?uestion mark"=>"=sign", "hello"=>"g\xC3\xBCnther"
2034
+ }
1924
2035
  end
1925
2036
 
1926
2037
  it "should have the correct query string after flag hash assignment" do
@@ -1933,6 +2044,12 @@ describe Addressable::URI, " when parsed from " +
1933
2044
  }
1934
2045
  end
1935
2046
 
2047
+ it "should raise an error if query values are set to a bogus type" do
2048
+ (lambda do
2049
+ @uri.query_values = "bogus"
2050
+ end).should raise_error(TypeError)
2051
+ end
2052
+
1936
2053
  it "should have the correct fragment after assignment" do
1937
2054
  @uri.fragment = "newfragment"
1938
2055
  @uri.fragment.should == "newfragment"
@@ -2023,7 +2140,7 @@ describe Addressable::URI, " when parsed from " +
2023
2140
  end
2024
2141
  end
2025
2142
 
2026
- describe Addressable::URI, " when parsed from " +
2143
+ describe Addressable::URI, "when parsed from " +
2027
2144
  "'http://user@example.com'" do
2028
2145
  before do
2029
2146
  @uri = Addressable::URI.parse("http://user@example.com")
@@ -2111,7 +2228,7 @@ describe Addressable::URI, " when parsed from " +
2111
2228
  end
2112
2229
  end
2113
2230
 
2114
- describe Addressable::URI, " when parsed from " +
2231
+ describe Addressable::URI, "when parsed from " +
2115
2232
  "'http://user:@example.com'" do
2116
2233
  before do
2117
2234
  @uri = Addressable::URI.parse("http://user:@example.com")
@@ -2166,7 +2283,7 @@ describe Addressable::URI, " when parsed from " +
2166
2283
  end
2167
2284
  end
2168
2285
 
2169
- describe Addressable::URI, " when parsed from " +
2286
+ describe Addressable::URI, "when parsed from " +
2170
2287
  "'http://:pass@example.com'" do
2171
2288
  before do
2172
2289
  @uri = Addressable::URI.parse("http://:pass@example.com")
@@ -2226,7 +2343,7 @@ describe Addressable::URI, " when parsed from " +
2226
2343
  end
2227
2344
  end
2228
2345
 
2229
- describe Addressable::URI, " when parsed from " +
2346
+ describe Addressable::URI, "when parsed from " +
2230
2347
  "'http://:@example.com'" do
2231
2348
  before do
2232
2349
  @uri = Addressable::URI.parse("http://:@example.com")
@@ -2282,7 +2399,7 @@ describe Addressable::URI, " when parsed from " +
2282
2399
  end
2283
2400
  end
2284
2401
 
2285
- describe Addressable::URI, " when parsed from " +
2402
+ describe Addressable::URI, "when parsed from " +
2286
2403
  "'#example'" do
2287
2404
  before do
2288
2405
  @uri = Addressable::URI.parse("#example")
@@ -2309,7 +2426,7 @@ describe Addressable::URI, " when parsed from " +
2309
2426
  end
2310
2427
  end
2311
2428
 
2312
- describe Addressable::URI, " when parsed from " +
2429
+ describe Addressable::URI, "when parsed from " +
2313
2430
  "the network-path reference '//example.com/'" do
2314
2431
  before do
2315
2432
  @uri = Addressable::URI.parse("//example.com/")
@@ -2337,7 +2454,7 @@ describe Addressable::URI, " when parsed from " +
2337
2454
  end
2338
2455
  end
2339
2456
 
2340
- describe Addressable::URI, " when parsed from " +
2457
+ describe Addressable::URI, "when parsed from " +
2341
2458
  "'feed://http://example.com/'" do
2342
2459
  before do
2343
2460
  @uri = Addressable::URI.parse("feed://http://example.com/")
@@ -2352,7 +2469,7 @@ describe Addressable::URI, " when parsed from " +
2352
2469
  end
2353
2470
  end
2354
2471
 
2355
- describe Addressable::URI, " when parsed from " +
2472
+ describe Addressable::URI, "when parsed from " +
2356
2473
  "'feed:http://example.com/'" do
2357
2474
  before do
2358
2475
  @uri = Addressable::URI.parse("feed:http://example.com/")
@@ -2381,7 +2498,7 @@ describe Addressable::URI, "when parsed from " +
2381
2498
  end
2382
2499
  end
2383
2500
 
2384
- describe Addressable::URI, " when parsed from " +
2501
+ describe Addressable::URI, "when parsed from " +
2385
2502
  "'http://example.com/indirect/path/./to/../resource/'" do
2386
2503
  before do
2387
2504
  @uri = Addressable::URI.parse(
@@ -2411,7 +2528,7 @@ describe Addressable::URI, " when parsed from " +
2411
2528
  end
2412
2529
  end
2413
2530
 
2414
- describe Addressable::URI, " when parsed from " +
2531
+ describe Addressable::URI, "when parsed from " +
2415
2532
  "'http://under_score.example.com/'" do
2416
2533
  it "should not cause an error" do
2417
2534
  (lambda do
@@ -2420,7 +2537,7 @@ describe Addressable::URI, " when parsed from " +
2420
2537
  end
2421
2538
  end
2422
2539
 
2423
- describe Addressable::URI, " when parsed from " +
2540
+ describe Addressable::URI, "when parsed from " +
2424
2541
  "'./this:that'" do
2425
2542
  before do
2426
2543
  @uri = Addressable::URI.parse("./this:that")
@@ -2450,7 +2567,26 @@ describe Addressable::URI, "when parsed from " +
2450
2567
  end
2451
2568
  end
2452
2569
 
2453
- describe Addressable::URI, " when parsed from '?one=1&two=2&three=3'" do
2570
+ describe Addressable::URI, "when parsed from '?'" do
2571
+ before do
2572
+ @uri = Addressable::URI.parse("?")
2573
+ end
2574
+
2575
+ it "should have the correct subscript notation query values" do
2576
+ @uri.query_values.should == {}
2577
+ @uri.query_values(:notation => :subscript).should == {}
2578
+ end
2579
+
2580
+ it "should have the correct dot notation query values" do
2581
+ @uri.query_values(:notation => :dot).should == {}
2582
+ end
2583
+
2584
+ it "should have the correct flat notation query values" do
2585
+ @uri.query_values(:notation => :flat).should == {}
2586
+ end
2587
+ end
2588
+
2589
+ describe Addressable::URI, "when parsed from '?one=1&two=2&three=3'" do
2454
2590
  before do
2455
2591
  @uri = Addressable::URI.parse("?one=1&two=2&three=3")
2456
2592
  end
@@ -2466,7 +2602,7 @@ describe Addressable::URI, " when parsed from '?one=1&two=2&three=3'" do
2466
2602
  end
2467
2603
  end
2468
2604
 
2469
- describe Addressable::URI, " when parsed from '?one[two][three]=four'" do
2605
+ describe Addressable::URI, "when parsed from '?one[two][three]=four'" do
2470
2606
  before do
2471
2607
  @uri = Addressable::URI.parse("?one[two][three]=four")
2472
2608
  end
@@ -2482,7 +2618,7 @@ describe Addressable::URI, " when parsed from '?one[two][three]=four'" do
2482
2618
  end
2483
2619
  end
2484
2620
 
2485
- describe Addressable::URI, " when parsed from '?one.two.three=four'" do
2621
+ describe Addressable::URI, "when parsed from '?one.two.three=four'" do
2486
2622
  before do
2487
2623
  @uri = Addressable::URI.parse("?one.two.three=four")
2488
2624
  end
@@ -2500,7 +2636,7 @@ describe Addressable::URI, " when parsed from '?one.two.three=four'" do
2500
2636
  end
2501
2637
  end
2502
2638
 
2503
- describe Addressable::URI, " when parsed from " +
2639
+ describe Addressable::URI, "when parsed from " +
2504
2640
  "'?one[two][three]=four&one[two][five]=six'" do
2505
2641
  before do
2506
2642
  @uri = Addressable::URI.parse("?one[two][three]=four&one[two][five]=six")
@@ -2520,7 +2656,7 @@ describe Addressable::URI, " when parsed from " +
2520
2656
  end
2521
2657
  end
2522
2658
 
2523
- describe Addressable::URI, " when parsed from " +
2659
+ describe Addressable::URI, "when parsed from " +
2524
2660
  "'?one.two.three=four&one.two.five=six'" do
2525
2661
  before do
2526
2662
  @uri = Addressable::URI.parse("?one.two.three=four&one.two.five=six")
@@ -2540,7 +2676,7 @@ describe Addressable::URI, " when parsed from " +
2540
2676
  end
2541
2677
  end
2542
2678
 
2543
- describe Addressable::URI, " when parsed from " +
2679
+ describe Addressable::URI, "when parsed from " +
2544
2680
  "'?one[two][three][]=four&one[two][three][]=five'" do
2545
2681
  before do
2546
2682
  @uri = Addressable::URI.parse(
@@ -2548,7 +2684,7 @@ describe Addressable::URI, " when parsed from " +
2548
2684
  )
2549
2685
  end
2550
2686
 
2551
- it "should have the correct dot notation query values" do
2687
+ it "should have the correct subscript notation query values" do
2552
2688
  @uri.query_values(:notation => :subscript).should == {
2553
2689
  "one" => {"two" => {"three" => ["four", "five"]}}
2554
2690
  }
@@ -2561,7 +2697,22 @@ describe Addressable::URI, " when parsed from " +
2561
2697
  end
2562
2698
  end
2563
2699
 
2564
- describe Addressable::URI, " when parsed from " +
2700
+ describe Addressable::URI, "when parsed from " +
2701
+ "'?one[two][three][0]=four&one[two][three][1]=five'" do
2702
+ before do
2703
+ @uri = Addressable::URI.parse(
2704
+ "?one[two][three][0]=four&one[two][three][1]=five"
2705
+ )
2706
+ end
2707
+
2708
+ it "should have the correct subscript notation query values" do
2709
+ @uri.query_values(:notation => :subscript).should == {
2710
+ "one" => {"two" => {"three" => ["four", "five"]}}
2711
+ }
2712
+ end
2713
+ end
2714
+
2715
+ describe Addressable::URI, "when parsed from " +
2565
2716
  "'http://www.詹姆斯.com/'" do
2566
2717
  before do
2567
2718
  @uri = Addressable::URI.parse("http://www.詹姆斯.com/")
@@ -2578,7 +2729,7 @@ describe Addressable::URI, " when parsed from " +
2578
2729
  end
2579
2730
  end
2580
2731
 
2581
- describe Addressable::URI, " when parsed from " +
2732
+ describe Addressable::URI, "when parsed from " +
2582
2733
  "'http://www.詹姆斯.com/ some spaces /'" do
2583
2734
  before do
2584
2735
  @uri = Addressable::URI.parse("http://www.詹姆斯.com/ some spaces /")
@@ -2597,7 +2748,7 @@ describe Addressable::URI, " when parsed from " +
2597
2748
  end
2598
2749
  end
2599
2750
 
2600
- describe Addressable::URI, " when parsed from " +
2751
+ describe Addressable::URI, "when parsed from " +
2601
2752
  "'http://www.xn--8ws00zhy3a.com/'" do
2602
2753
  before do
2603
2754
  @uri = Addressable::URI.parse("http://www.xn--8ws00zhy3a.com/")
@@ -2606,9 +2757,17 @@ describe Addressable::URI, " when parsed from " +
2606
2757
  it "should be displayed as http://www.詹姆斯.com/" do
2607
2758
  @uri.display_uri.to_s.should == "http://www.詹姆斯.com/"
2608
2759
  end
2760
+
2761
+ it "should properly force the encoding" do
2762
+ display_string = @uri.display_uri.to_str
2763
+ display_string.should == "http://www.詹姆斯.com/"
2764
+ if display_string.respond_to?(:encoding)
2765
+ display_string.encoding.to_s.should == Encoding::UTF_8.to_s
2766
+ end
2767
+ end
2609
2768
  end
2610
2769
 
2611
- describe Addressable::URI, " when parsed from " +
2770
+ describe Addressable::URI, "when parsed from " +
2612
2771
  "'http://www.詹姆斯.com/atomtests/iri/詹.html'" do
2613
2772
  before do
2614
2773
  @uri = Addressable::URI.parse("http://www.詹姆斯.com/atomtests/iri/詹.html")
@@ -2623,7 +2782,7 @@ describe Addressable::URI, " when parsed from " +
2623
2782
  end
2624
2783
  end
2625
2784
 
2626
- describe Addressable::URI, " when parsed from a percent-encoded IRI" do
2785
+ describe Addressable::URI, "when parsed from a percent-encoded IRI" do
2627
2786
  before do
2628
2787
  @uri = Addressable::URI.parse(
2629
2788
  "http://www.%E3%81%BB%E3%82%93%E3%81%A8%E3%81%86%E3%81%AB%E3%81%AA" +
@@ -2936,47 +3095,6 @@ describe Addressable::URI, "with a base uri of 'http://a/b/c/d;p?q'" do
2936
3095
  end
2937
3096
  end
2938
3097
 
2939
- describe Addressable::URI, "when extracting from an arbitrary text" do
2940
- before do
2941
- @text = File.open(File.expand_path(
2942
- File.dirname(__FILE__) + "/../data/rfc3986.txt")) { |file| file.read }
2943
- end
2944
-
2945
- it "should have all obvious URIs extractable from it" do
2946
- @uris = Addressable::URI.extract(@text)
2947
- @uris.should include("http://www.w3.org/People/Berners-Lee/")
2948
- @uris.should include("http://roy.gbiv.com/")
2949
- @uris.should include("http://larry.masinter.net/")
2950
- @uris = Addressable::URI.extract(@text,
2951
- :base => "http://example.com/", :parse => true)
2952
- @uris.should include(
2953
- Addressable::URI.parse("http://www.w3.org/People/Berners-Lee/"))
2954
- @uris.should include(
2955
- Addressable::URI.parse("http://roy.gbiv.com/"))
2956
- @uris.should include(
2957
- Addressable::URI.parse("http://larry.masinter.net/"))
2958
- end
2959
- end
2960
-
2961
- describe Addressable::URI, "when extracting from an arbitrary text " +
2962
- "containing invalid URIs" do
2963
- before do
2964
- @text = <<-TEXT
2965
- This is an invalid URI:
2966
- http://example.com:bogus/path/to/something/
2967
- This is a valid URI:
2968
- http://example.com:80/path/to/something/
2969
- TEXT
2970
- end
2971
-
2972
- it "should ignore invalid URIs when extracting" do
2973
- @uris = Addressable::URI.extract(@text)
2974
- @uris.should include("http://example.com:80/path/to/something/")
2975
- @uris.should_not include("http://example.com:bogus/path/to/something/")
2976
- @uris.size.should == 1
2977
- end
2978
- end
2979
-
2980
3098
  describe Addressable::URI, "when converting the path " +
2981
3099
  "'relative/path/to/something'" do
2982
3100
  before do
@@ -2986,13 +3104,13 @@ describe Addressable::URI, "when converting the path " +
2986
3104
  it "should convert to " +
2987
3105
  "\'relative/path/to/something\'" do
2988
3106
  @uri = Addressable::URI.convert_path(@path)
2989
- @uri.to_s.should == "relative/path/to/something"
3107
+ @uri.to_str.should == "relative/path/to/something"
2990
3108
  end
2991
3109
 
2992
3110
  it "should join with an absolute file path correctly" do
2993
3111
  @base = Addressable::URI.convert_path("/absolute/path/")
2994
3112
  @uri = Addressable::URI.convert_path(@path)
2995
- (@base + @uri).to_s.should ==
3113
+ (@base + @uri).to_str.should ==
2996
3114
  "file:///absolute/path/relative/path/to/something"
2997
3115
  end
2998
3116
  end
@@ -3017,12 +3135,12 @@ describe Addressable::URI, "when given the root directory" do
3017
3135
  if RUBY_PLATFORM =~ /mswin/
3018
3136
  it "should convert to \'file:///c:/\'" do
3019
3137
  @uri = Addressable::URI.convert_path(@path)
3020
- @uri.to_s.should == "file:///c:/"
3138
+ @uri.to_str.should == "file:///c:/"
3021
3139
  end
3022
3140
  else
3023
3141
  it "should convert to \'file:///\'" do
3024
3142
  @uri = Addressable::URI.convert_path(@path)
3025
- @uri.to_s.should == "file:///"
3143
+ @uri.to_str.should == "file:///"
3026
3144
  end
3027
3145
  end
3028
3146
  end
@@ -3035,11 +3153,11 @@ describe Addressable::URI, "when given the path '/home/user/'" do
3035
3153
  it "should convert to " +
3036
3154
  "\'file:///home/user/\'" do
3037
3155
  @uri = Addressable::URI.convert_path(@path)
3038
- @uri.to_s.should == "file:///home/user/"
3156
+ @uri.to_str.should == "file:///home/user/"
3039
3157
  end
3040
3158
  end
3041
3159
 
3042
- describe Addressable::URI, " when given the path " +
3160
+ describe Addressable::URI, "when given the path " +
3043
3161
  "'c:\\windows\\My Documents 100%20\\foo.txt'" do
3044
3162
  before do
3045
3163
  @path = "c:\\windows\\My Documents 100%20\\foo.txt"
@@ -3048,11 +3166,11 @@ describe Addressable::URI, " when given the path " +
3048
3166
  it "should convert to " +
3049
3167
  "\'file:///c:/windows/My%20Documents%20100%20/foo.txt\'" do
3050
3168
  @uri = Addressable::URI.convert_path(@path)
3051
- @uri.to_s.should == "file:///c:/windows/My%20Documents%20100%20/foo.txt"
3169
+ @uri.to_str.should == "file:///c:/windows/My%20Documents%20100%20/foo.txt"
3052
3170
  end
3053
3171
  end
3054
3172
 
3055
- describe Addressable::URI, " when given the path " +
3173
+ describe Addressable::URI, "when given the path " +
3056
3174
  "'file://c:\\windows\\My Documents 100%20\\foo.txt'" do
3057
3175
  before do
3058
3176
  @path = "file://c:\\windows\\My Documents 100%20\\foo.txt"
@@ -3061,11 +3179,11 @@ describe Addressable::URI, " when given the path " +
3061
3179
  it "should convert to " +
3062
3180
  "\'file:///c:/windows/My%20Documents%20100%20/foo.txt\'" do
3063
3181
  @uri = Addressable::URI.convert_path(@path)
3064
- @uri.to_s.should == "file:///c:/windows/My%20Documents%20100%20/foo.txt"
3182
+ @uri.to_str.should == "file:///c:/windows/My%20Documents%20100%20/foo.txt"
3065
3183
  end
3066
3184
  end
3067
3185
 
3068
- describe Addressable::URI, " when given the path " +
3186
+ describe Addressable::URI, "when given the path " +
3069
3187
  "'file:c:\\windows\\My Documents 100%20\\foo.txt'" do
3070
3188
  before do
3071
3189
  @path = "file:c:\\windows\\My Documents 100%20\\foo.txt"
@@ -3074,11 +3192,11 @@ describe Addressable::URI, " when given the path " +
3074
3192
  it "should convert to " +
3075
3193
  "\'file:///c:/windows/My%20Documents%20100%20/foo.txt\'" do
3076
3194
  @uri = Addressable::URI.convert_path(@path)
3077
- @uri.to_s.should == "file:///c:/windows/My%20Documents%20100%20/foo.txt"
3195
+ @uri.to_str.should == "file:///c:/windows/My%20Documents%20100%20/foo.txt"
3078
3196
  end
3079
3197
  end
3080
3198
 
3081
- describe Addressable::URI, " when given the path " +
3199
+ describe Addressable::URI, "when given the path " +
3082
3200
  "'file:/c:\\windows\\My Documents 100%20\\foo.txt'" do
3083
3201
  before do
3084
3202
  @path = "file:/c:\\windows\\My Documents 100%20\\foo.txt"
@@ -3087,11 +3205,11 @@ describe Addressable::URI, " when given the path " +
3087
3205
  it "should convert to " +
3088
3206
  "\'file:///c:/windows/My%20Documents%20100%20/foo.txt\'" do
3089
3207
  @uri = Addressable::URI.convert_path(@path)
3090
- @uri.to_s.should == "file:///c:/windows/My%20Documents%20100%20/foo.txt"
3208
+ @uri.to_str.should == "file:///c:/windows/My%20Documents%20100%20/foo.txt"
3091
3209
  end
3092
3210
  end
3093
3211
 
3094
- describe Addressable::URI, " when given the path " +
3212
+ describe Addressable::URI, "when given the path " +
3095
3213
  "'file:///c|/windows/My%20Documents%20100%20/foo.txt'" do
3096
3214
  before do
3097
3215
  @path = "file:///c|/windows/My%20Documents%20100%20/foo.txt"
@@ -3100,7 +3218,7 @@ describe Addressable::URI, " when given the path " +
3100
3218
  it "should convert to " +
3101
3219
  "\'file:///c:/windows/My%20Documents%20100%20/foo.txt\'" do
3102
3220
  @uri = Addressable::URI.convert_path(@path)
3103
- @uri.to_s.should == "file:///c:/windows/My%20Documents%20100%20/foo.txt"
3221
+ @uri.to_str.should == "file:///c:/windows/My%20Documents%20100%20/foo.txt"
3104
3222
  end
3105
3223
  end
3106
3224
 
@@ -3111,480 +3229,7 @@ describe Addressable::URI, "when given an http protocol URI" do
3111
3229
 
3112
3230
  it "should not do any conversion at all" do
3113
3231
  @uri = Addressable::URI.convert_path(@path)
3114
- @uri.to_s.should == "http://example.com/"
3115
- end
3116
- end
3117
-
3118
- describe Addressable::URI, " when given the template pattern " +
3119
- "'http://example.com/search/{query}/' " +
3120
- "to be processed with the ExampleProcessor" do
3121
- before do
3122
- @pattern = "http://example.com/search/{query}/"
3123
- end
3124
-
3125
- it "should expand to " +
3126
- "'http://example.com/search/an+example+search+query/' " +
3127
- "with a mapping of {\"query\" => \"an example search query\"} " do
3128
- Addressable::URI.expand_template(
3129
- "http://example.com/search/{query}/",
3130
- {"query" => "an example search query"},
3131
- ExampleProcessor).to_s.should ==
3132
- "http://example.com/search/an+example+search+query/"
3133
- end
3134
-
3135
- it "should raise an error " +
3136
- "with a mapping of {\"query\" => \"invalid!\"}" do
3137
- (lambda do
3138
- Addressable::URI.expand_template(
3139
- "http://example.com/search/{query}/",
3140
- {"query" => "invalid!"},
3141
- ExampleProcessor).to_s
3142
- end).should raise_error
3143
- end
3144
- end
3145
-
3146
- # Section 3.3.1 of the URI Template draft v 01
3147
- describe Addressable::URI, " when given the mapping supplied in " +
3148
- "Section 3.3.1 of the URI Template draft v 01" do
3149
- before do
3150
- @mapping = {
3151
- "a" => "fred",
3152
- "b" => "barney",
3153
- "c" => "cheeseburger",
3154
- "d" => "one two three",
3155
- "e" => "20% tricky",
3156
- "f" => "",
3157
- "20" => "this-is-spinal-tap",
3158
- "scheme" => "https",
3159
- "p" => "quote=to+be+or+not+to+be",
3160
- "q" => "hullo#world"
3161
- }
3162
- end
3163
-
3164
- it "should result in 'http://example.org/page1#fred' " +
3165
- "when used to expand 'http://example.org/page1\#{a}'" do
3166
- Addressable::URI.expand_template(
3167
- "http://example.org/page1\#{a}",
3168
- @mapping
3169
- ).to_s.should == "http://example.org/page1#fred"
3170
- end
3171
-
3172
- it "should result in 'http://example.org/fred/barney/' " +
3173
- "when used to expand 'http://example.org/{a}/{b}/'" do
3174
- Addressable::URI.expand_template(
3175
- "http://example.org/{a}/{b}/",
3176
- @mapping
3177
- ).to_s.should == "http://example.org/fred/barney/"
3178
- end
3179
-
3180
- it "should result in 'http://example.org/fredbarney/' " +
3181
- "when used to expand 'http://example.org/{a}{b}/'" do
3182
- Addressable::URI.expand_template(
3183
- "http://example.org/{a}{b}/",
3184
- @mapping
3185
- ).to_s.should == "http://example.org/fredbarney/"
3186
- end
3187
-
3188
- it "should result in " +
3189
- "'http://example.com/order/cheeseburger/cheeseburger/cheeseburger/' " +
3190
- "when used to expand 'http://example.com/order/{c}/{c}/{c}/'" do
3191
- Addressable::URI.expand_template(
3192
- "http://example.com/order/{c}/{c}/{c}/",
3193
- @mapping
3194
- ).to_s.should ==
3195
- "http://example.com/order/cheeseburger/cheeseburger/cheeseburger/"
3196
- end
3197
-
3198
- it "should result in 'http://example.org/one%20two%20three' " +
3199
- "when used to expand 'http://example.org/{d}'" do
3200
- Addressable::URI.expand_template(
3201
- "http://example.org/{d}",
3202
- @mapping
3203
- ).to_s.should == "http://example.org/one%20two%20three"
3204
- end
3205
-
3206
- it "should result in 'http://example.org/20%25%20tricky' " +
3207
- "when used to expand 'http://example.org/{e}'" do
3208
- Addressable::URI.expand_template(
3209
- "http://example.org/{e}",
3210
- @mapping
3211
- ).to_s.should == "http://example.org/20%25%20tricky"
3212
- end
3213
-
3214
- it "should result in 'http://example.com//' " +
3215
- "when used to expand 'http://example.com/{f}/'" do
3216
- Addressable::URI.expand_template(
3217
- "http://example.com/{f}/",
3218
- @mapping
3219
- ).to_s.should == "http://example.com//"
3220
- end
3221
-
3222
- it "should result in " +
3223
- "'https://this-is-spinal-tap.example.org?date=&option=fred' " +
3224
- "when used to expand " +
3225
- "'{scheme}://{20}.example.org?date={wilma}&option={a}'" do
3226
- Addressable::URI.expand_template(
3227
- "{scheme}://{20}.example.org?date={wilma}&option={a}",
3228
- @mapping
3229
- ).to_s.should ==
3230
- "https://this-is-spinal-tap.example.org?date=&option=fred"
3231
- end
3232
-
3233
- # The v 01 draft conflicts with the v 03 draft here.
3234
- # The Addressable implementation uses v 03.
3235
- it "should result in " +
3236
- "'http://example.org?quote%3Dto%2Bbe%2Bor%2Bnot%2Bto%2Bbe' " +
3237
- "when used to expand 'http://example.org?{p}'" do
3238
- Addressable::URI.expand_template(
3239
- "http://example.org?{p}",
3240
- @mapping
3241
- ).to_s.should == "http://example.org?quote%3Dto%2Bbe%2Bor%2Bnot%2Bto%2Bbe"
3242
- end
3243
-
3244
- # The v 01 draft conflicts with the v 03 draft here.
3245
- # The Addressable implementation uses v 03.
3246
- it "should result in 'http://example.com/hullo%23world' " +
3247
- "when used to expand 'http://example.com/{q}'" do
3248
- Addressable::URI.expand_template(
3249
- "http://example.com/{q}",
3250
- @mapping
3251
- ).to_s.should == "http://example.com/hullo%23world"
3252
- end
3253
- end
3254
-
3255
- # Section 4.5 of the URI Template draft v 03
3256
- describe Addressable::URI, " when given the mapping supplied in " +
3257
- "Section 4.5 of the URI Template draft v 03" do
3258
- before do
3259
- @mapping = {
3260
- "foo" => "ϓ",
3261
- "bar" => "fred",
3262
- "baz" => "10,20,30",
3263
- "qux" => ["10","20","30"],
3264
- "corge" => [],
3265
- "grault" => "",
3266
- "garply" => "a/b/c",
3267
- "waldo" => "ben & jerrys",
3268
- "fred" => ["fred", "", "wilma"],
3269
- "plugh" => ["ẛ", "ṡ"],
3270
- "1-a_b.c" => "200"
3271
- }
3272
- end
3273
-
3274
- it "should result in 'http://example.org/?q=fred' " +
3275
- "when used to expand 'http://example.org/?q={bar}'" do
3276
- Addressable::URI.expand_template(
3277
- "http://example.org/?q={bar}",
3278
- @mapping
3279
- ).to_s.should == "http://example.org/?q=fred"
3280
- end
3281
-
3282
- it "should result in '/' " +
3283
- "when used to expand '/{xyzzy}'" do
3284
- Addressable::URI.expand_template(
3285
- "/{xyzzy}",
3286
- @mapping
3287
- ).to_s.should == "/"
3288
- end
3289
-
3290
- it "should result in " +
3291
- "'http://example.org/?foo=%CE%8E&bar=fred&baz=10%2C20%2C30' " +
3292
- "when used to expand " +
3293
- "'http://example.org/?{-join|&|foo,bar,xyzzy,baz}'" do
3294
- Addressable::URI.expand_template(
3295
- "http://example.org/?{-join|&|foo,bar,xyzzy,baz}",
3296
- @mapping
3297
- ).to_s.should ==
3298
- "http://example.org/?foo=%CE%8E&bar=fred&baz=10%2C20%2C30"
3299
- end
3300
-
3301
- it "should result in 'http://example.org/?d=10,20,30' " +
3302
- "when used to expand 'http://example.org/?d={-list|,|qux}'" do
3303
- Addressable::URI.expand_template(
3304
- "http://example.org/?d={-list|,|qux}",
3305
- @mapping
3306
- ).to_s.should == "http://example.org/?d=10,20,30"
3307
- end
3308
-
3309
- it "should result in 'http://example.org/?d=10&d=20&d=30' " +
3310
- "when used to expand 'http://example.org/?d={-list|&d=|qux}'" do
3311
- Addressable::URI.expand_template(
3312
- "http://example.org/?d={-list|&d=|qux}",
3313
- @mapping
3314
- ).to_s.should == "http://example.org/?d=10&d=20&d=30"
3315
- end
3316
-
3317
- it "should result in 'http://example.org/fredfred/a%2Fb%2Fc' " +
3318
- "when used to expand 'http://example.org/{bar}{bar}/{garply}'" do
3319
- Addressable::URI.expand_template(
3320
- "http://example.org/{bar}{bar}/{garply}",
3321
- @mapping
3322
- ).to_s.should == "http://example.org/fredfred/a%2Fb%2Fc"
3323
- end
3324
-
3325
- it "should result in 'http://example.org/fred/fred//wilma' " +
3326
- "when used to expand 'http://example.org/{bar}{-prefix|/|fred}'" do
3327
- Addressable::URI.expand_template(
3328
- "http://example.org/{bar}{-prefix|/|fred}",
3329
- @mapping
3330
- ).to_s.should == "http://example.org/fred/fred//wilma"
3331
- end
3332
-
3333
- it "should result in ':%E1%B9%A1:%E1%B9%A1:' " +
3334
- "when used to expand '{-neg|:|corge}{-suffix|:|plugh}'" do
3335
- Addressable::URI.expand_template(
3336
- "{-neg|:|corge}{-suffix|:|plugh}",
3337
- @mapping
3338
- ).to_s.should == ":%E1%B9%A1:%E1%B9%A1:"
3339
- end
3340
-
3341
- it "should result in '../ben%20%26%20jerrys/' " +
3342
- "when used to expand '../{waldo}/'" do
3343
- Addressable::URI.expand_template(
3344
- "../{waldo}/",
3345
- @mapping
3346
- ).to_s.should == "../ben%20%26%20jerrys/"
3347
- end
3348
-
3349
- it "should result in 'telnet:192.0.2.16:80' " +
3350
- "when used to expand 'telnet:192.0.2.16{-opt|:80|grault}'" do
3351
- Addressable::URI.expand_template(
3352
- "telnet:192.0.2.16{-opt|:80|grault}",
3353
- @mapping
3354
- ).to_s.should == "telnet:192.0.2.16:80"
3355
- end
3356
-
3357
- it "should result in ':200:' " +
3358
- "when used to expand ':{1-a_b.c}:'" do
3359
- Addressable::URI.expand_template(
3360
- ":{1-a_b.c}:",
3361
- @mapping
3362
- ).to_s.should == ":200:"
3363
- end
3364
- end
3365
-
3366
- describe Addressable::URI, "when given a mapping that contains a " +
3367
- "template-var within a value" do
3368
- before do
3369
- @mapping = {
3370
- "a" => "{b}",
3371
- "b" => "barney",
3372
- }
3373
- end
3374
-
3375
- it "should result in 'http://example.com/%7Bb%7D/barney/' " +
3376
- "when used to expand 'http://example.com/{a}/{b}/'" do
3377
- Addressable::URI.expand_template(
3378
- "http://example.com/{a}/{b}/",
3379
- @mapping).to_s.should == "http://example.com/%7Bb%7D/barney/"
3380
- end
3381
-
3382
- it "should result in 'http://example.com//%7Bb%7D/' " +
3383
- "when used to expand 'http://example.com/{-opt|foo|foo}/{a}/'" do
3384
- Addressable::URI.expand_template(
3385
- "http://example.com/{-opt|foo|foo}/{a}/",
3386
- @mapping).to_s.should == "http://example.com//%7Bb%7D/"
3387
- end
3388
-
3389
- it "should result in 'http://example.com//%7Bb%7D/' " +
3390
- "when used to expand 'http://example.com/{-neg|foo|b}/{a}/'" do
3391
- Addressable::URI.expand_template(
3392
- "http://example.com/{-neg|foo|b}/{a}/",
3393
- @mapping).to_s.should == "http://example.com//%7Bb%7D/"
3394
- end
3395
-
3396
- it "should result in 'http://example.com//barney/%7Bb%7D/' " +
3397
- "when used to expand 'http://example.com/{-prefix|/|b}/{a}/'" do
3398
- Addressable::URI.expand_template(
3399
- "http://example.com/{-prefix|/|b}/{a}/",
3400
- @mapping).to_s.should == "http://example.com//barney/%7Bb%7D/"
3401
- end
3402
-
3403
- it "should result in 'http://example.com/barney//%7Bb%7D/' " +
3404
- "when used to expand 'http://example.com/{-suffix|/|b}/{a}/'" do
3405
- Addressable::URI.expand_template(
3406
- "http://example.com/{-suffix|/|b}/{a}/",
3407
- @mapping).to_s.should == "http://example.com/barney//%7Bb%7D/"
3408
- end
3409
-
3410
- it "should result in 'http://example.com/%7Bb%7D/?b=barney&c=42' " +
3411
- "when used to expand 'http://example.com/{a}/?{-join|&|b,c=42}'" do
3412
- Addressable::URI.expand_template(
3413
- "http://example.com/{a}/?{-join|&|b,c=42}",
3414
- @mapping).to_s.should == "http://example.com/%7Bb%7D/?b=barney&c=42"
3415
- end
3416
-
3417
- it "should result in 'http://example.com/42/?b=barney' " +
3418
- "when used to expand 'http://example.com/{c=42}/?{-join|&|b}'" do
3419
- Addressable::URI.expand_template(
3420
- "http://example.com/{c=42}/?{-join|&|b}",
3421
- @mapping).to_s.should == "http://example.com/42/?b=barney"
3422
- end
3423
- end
3424
-
3425
- describe Addressable::URI, "when given a single variable mapping" do
3426
- before do
3427
- @mapping = {
3428
- "foo" => "fred"
3429
- }
3430
- end
3431
-
3432
- it "should result in 'fred' when used to expand '{foo}'" do
3433
- Addressable::URI.expand_template(
3434
- "{foo}",
3435
- @mapping
3436
- ).to_s.should == "fred"
3437
- end
3438
-
3439
- it "should result in 'wilma' when used to expand '{bar=wilma}'" do
3440
- Addressable::URI.expand_template(
3441
- "{bar=wilma}",
3442
- @mapping
3443
- ).to_s.should == "wilma"
3444
- end
3445
-
3446
- it "should result in '' when used to expand '{baz}'" do
3447
- Addressable::URI.expand_template(
3448
- "{baz}",
3449
- @mapping
3450
- ).to_s.should == ""
3451
- end
3452
- end
3453
-
3454
- describe Addressable::URI, "when given a simple mapping" do
3455
- before do
3456
- @mapping = {
3457
- "foo" => "fred",
3458
- "bar" => "barney",
3459
- "baz" => ""
3460
- }
3461
- end
3462
-
3463
- it "should result in 'foo=fred&bar=barney&baz=' when used to expand " +
3464
- "'{-join|&|foo,bar,baz,qux}'" do
3465
- Addressable::URI.expand_template(
3466
- "{-join|&|foo,bar,baz,qux}",
3467
- @mapping
3468
- ).to_s.should == "foo=fred&bar=barney&baz="
3469
- end
3470
-
3471
- it "should result in 'bar=barney' when used to expand " +
3472
- "'{-join|&|bar}'" do
3473
- Addressable::URI.expand_template(
3474
- "{-join|&|bar}",
3475
- @mapping
3476
- ).to_s.should == "bar=barney"
3477
- end
3478
-
3479
- it "should result in '' when used to expand " +
3480
- "'{-join|&|qux}'" do
3481
- Addressable::URI.expand_template(
3482
- "{-join|&|qux}",
3483
- @mapping
3484
- ).to_s.should == ""
3485
- end
3486
- end
3487
-
3488
- describe Addressable::URI, "when given a mapping containing values " +
3489
- "that are already percent-encoded" do
3490
- before do
3491
- @mapping = {
3492
- "a" => "%7Bb%7D"
3493
- }
3494
- end
3495
-
3496
- it "should result in 'http://example.com/%257Bb%257D/' " +
3497
- "when used to expand 'http://example.com/{a}/'" do
3498
- Addressable::URI.expand_template(
3499
- "http://example.com/{a}/",
3500
- @mapping).to_s.should == "http://example.com/%257Bb%257D/"
3501
- end
3502
- end
3503
-
3504
- describe Addressable::URI, "when given a mapping containing bogus values" do
3505
- it "should raise a TypeError" do
3506
- (lambda do
3507
- Addressable::URI.expand_template(
3508
- "http://example.com/{bogus}/", {
3509
- "bogus" => 42
3510
- }
3511
- )
3512
- end).should raise_error(TypeError)
3513
- end
3514
- end
3515
-
3516
- describe Addressable::URI, "when given a pattern with bogus operators" do
3517
- it "should raise an InvalidTemplateOperatorError" do
3518
- (lambda do
3519
- Addressable::URI.expand_template(
3520
- "http://example.com/{-bogus|/|a,b,c}/", {
3521
- "a" => "a", "b" => "b", "c" => "c"
3522
- }
3523
- )
3524
- end).should raise_error(Addressable::URI::InvalidTemplateOperatorError)
3525
- end
3526
-
3527
- it "should raise an InvalidTemplateOperatorError" do
3528
- (lambda do
3529
- Addressable::URI.expand_template(
3530
- "http://example.com/{-prefix|/|a,b,c}/", {
3531
- "a" => "a", "b" => "b", "c" => "c"
3532
- }
3533
- )
3534
- end).should raise_error(Addressable::URI::InvalidTemplateOperatorError)
3535
- end
3536
-
3537
- it "should raise an InvalidTemplateOperatorError" do
3538
- (lambda do
3539
- Addressable::URI.expand_template(
3540
- "http://example.com/{-suffix|/|a,b,c}/", {
3541
- "a" => "a", "b" => "b", "c" => "c"
3542
- }
3543
- )
3544
- end).should raise_error(Addressable::URI::InvalidTemplateOperatorError)
3545
- end
3546
-
3547
- it "should raise an InvalidTemplateOperatorError" do
3548
- (lambda do
3549
- Addressable::URI.expand_template(
3550
- "http://example.com/{-join|/|a,b,c}/", {
3551
- "a" => ["a"], "b" => ["b"], "c" => "c"
3552
- }
3553
- )
3554
- end).should raise_error(Addressable::URI::InvalidTemplateOperatorError)
3555
- end
3556
-
3557
- it "should raise an InvalidTemplateOperatorError" do
3558
- (lambda do
3559
- Addressable::URI.expand_template(
3560
- "http://example.com/{-list|/|a,b,c}/", {
3561
- "a" => ["a"], "b" => ["b"], "c" => "c"
3562
- }
3563
- )
3564
- end).should raise_error(Addressable::URI::InvalidTemplateOperatorError)
3565
- end
3566
- end
3567
-
3568
- describe Addressable::URI, "when given a mapping that contains an Array" do
3569
- before do
3570
- @mapping = {"query" => "an example search query".split(" ")}
3571
- end
3572
-
3573
- it "should result in 'http://example.com/search/an+example+search+query/'" +
3574
- " when used to expand 'http://example.com/search/{-list|+|query}/'" do
3575
- Addressable::URI.expand_template(
3576
- "http://example.com/search/{-list|+|query}/",
3577
- @mapping).to_s.should ==
3578
- "http://example.com/search/an+example+search+query/"
3579
- end
3580
-
3581
- it "should result in 'http://example.com/search/an+example+search+query/'" +
3582
- " when used to expand 'http://example.com/search/{-list|+|query}/'" +
3583
- " with a NoOpProcessor" do
3584
- Addressable::URI.expand_template(
3585
- "http://example.com/search/{-list|+|query}/",
3586
- @mapping, NoOpProcessor).to_s.should ==
3587
- "http://example.com/search/an+example+search+query/"
3232
+ @uri.to_str.should == "http://example.com/"
3588
3233
  end
3589
3234
  end
3590
3235
 
@@ -3598,7 +3243,7 @@ class SuperString
3598
3243
  end
3599
3244
  end
3600
3245
 
3601
- describe Addressable::URI, " when parsing a non-String object" do
3246
+ describe Addressable::URI, "when parsing a non-String object" do
3602
3247
  it "should correctly parse anything with a 'to_str' method" do
3603
3248
  Addressable::URI.parse(SuperString.new(42))
3604
3249
  end
@@ -3606,7 +3251,7 @@ describe Addressable::URI, " when parsing a non-String object" do
3606
3251
  it "should raise a TypeError for objects than cannot be converted" do
3607
3252
  (lambda do
3608
3253
  Addressable::URI.parse(42)
3609
- end).should raise_error(TypeError)
3254
+ end).should raise_error(TypeError, "Can't convert Fixnum into String.")
3610
3255
  end
3611
3256
 
3612
3257
  it "should correctly parse heuristically anything with a 'to_str' method" do
@@ -3616,7 +3261,7 @@ describe Addressable::URI, " when parsing a non-String object" do
3616
3261
  it "should raise a TypeError for objects than cannot be converted" do
3617
3262
  (lambda do
3618
3263
  Addressable::URI.heuristic_parse(42)
3619
- end).should raise_error(TypeError)
3264
+ end).should raise_error(TypeError, "Can't convert Fixnum into String.")
3620
3265
  end
3621
3266
  end
3622
3267
 
@@ -3698,514 +3343,50 @@ describe Addressable::URI, "when encoding a bogus object" do
3698
3343
  end
3699
3344
  end
3700
3345
 
3701
- describe Addressable::URI, " when parsed from " +
3702
- "'/'" do
3703
- before do
3704
- @uri = Addressable::URI.parse("/")
3705
- end
3706
-
3707
- it "should have the correct mapping when extracting values " +
3708
- "using the pattern '/'" do
3709
- @uri.extract_mapping("/").should == {}
3710
- end
3711
- end
3712
-
3713
- describe Addressable::URI, " when parsed from '/one/'" do
3714
- before do
3715
- @uri = Addressable::URI.parse("/one/")
3716
- end
3717
-
3718
- it "should not match the pattern '/two/'" do
3719
- @uri.extract_mapping("/two/").should == nil
3720
- end
3721
-
3722
- it "should have the correct mapping when extracting values " +
3723
- "using the pattern '/{number}/'" do
3724
- @uri.extract_mapping("/{number}/").should == {"number" => "one"}
3725
- end
3726
- end
3727
-
3728
- describe Addressable::URI, " when parsed from '/one/two/'" do
3729
- before do
3730
- @uri = Addressable::URI.parse("/one/two/")
3731
- end
3732
-
3733
- it "should not match the pattern '/{number}/' " +
3734
- "with the SlashlessProcessor" do
3735
- @uri.extract_mapping("/{number}/", SlashlessProcessor).should == nil
3736
- end
3737
-
3738
- it "should have the correct mapping when extracting values " +
3739
- "using the pattern '/{number}/' without a processor" do
3740
- @uri.extract_mapping("/{number}/").should == {
3741
- "number" => "one/two"
3742
- }
3743
- end
3744
-
3745
- it "should have the correct mapping when extracting values " +
3746
- "using the pattern '/{first}/{second}/' with the SlashlessProcessor" do
3747
- @uri.extract_mapping("/{first}/{second}/", SlashlessProcessor).should == {
3748
- "first" => "one",
3749
- "second" => "two"
3750
- }
3751
- end
3752
- end
3753
-
3754
- describe Addressable::URI, " when parsed from " +
3755
- "'http://example.com/search/an+example+search+query/'" do
3756
- before do
3757
- @uri = Addressable::URI.parse(
3758
- "http://example.com/search/an+example+search+query/")
3759
- end
3760
-
3761
- it "should have the correct mapping when extracting values using " +
3762
- "the pattern 'http://example.com/search/{query}/' with the " +
3763
- "ExampleProcessor" do
3764
- @uri.extract_mapping(
3765
- "http://example.com/search/{query}/", ExampleProcessor
3766
- ).should == {
3767
- "query" => "an example search query"
3768
- }
3769
- end
3770
-
3771
- it "should have the correct mapping when extracting values " +
3772
- "using the pattern " +
3773
- "'http://example.com/search/{-list|+|query}/'" do
3774
- @uri.extract_mapping(
3775
- "http://example.com/search/{-list|+|query}/"
3776
- ).should == {
3777
- "query" => ["an", "example", "search", "query"]
3778
- }
3779
- end
3780
-
3781
- it "should return nil when extracting values using " +
3782
- "a non-matching pattern" do
3783
- @uri.extract_mapping(
3784
- "http://bogus.com/{thingy}/"
3785
- ).should == nil
3786
- end
3787
- end
3788
-
3789
- describe Addressable::URI, " when parsed from " +
3790
- "'http://example.com/a/b/c/'" do
3791
- before do
3792
- @uri = Addressable::URI.parse(
3793
- "http://example.com/a/b/c/")
3794
- end
3795
-
3796
- it "should have the correct mapping when extracting values " +
3797
- "using the pattern " +
3798
- "'http://example.com/{first}/{second}/' with the ExampleProcessor" do
3799
- @uri.extract_mapping(
3800
- "http://example.com/{first}/{second}/", ExampleProcessor
3801
- ).should == {
3802
- "first" => "a",
3803
- "second" => "b/c"
3804
- }
3805
- end
3806
-
3807
- it "should have the correct mapping when extracting values " +
3808
- "using the pattern " +
3809
- "'http://example.com/{first}/{-list|/|second}/'" do
3810
- @uri.extract_mapping(
3811
- "http://example.com/{first}/{-list|/|second}/"
3812
- ).should == {
3813
- "first" => "a",
3814
- "second" => ["b", "c"]
3815
- }
3816
- end
3817
-
3818
- it "should have the correct mapping when extracting values " +
3819
- "using the pattern " +
3820
- "'http://example.com/{first}/{-list|/|rot13}/' " +
3821
- "with the ExampleProcessor" do
3822
- @uri.extract_mapping(
3823
- "http://example.com/{first}/{-list|/|rot13}/",
3824
- ExampleProcessor
3825
- ).should == {
3826
- "first" => "a",
3827
- "rot13" => ["o", "p"]
3828
- }
3829
- end
3830
-
3831
- it "should have the correct mapping when extracting values " +
3832
- "using the pattern " +
3833
- "'http://example.com/{-list|/|rot13}/' " +
3834
- "with the ExampleProcessor" do
3835
- @uri.extract_mapping(
3836
- "http://example.com/{-list|/|rot13}/",
3837
- ExampleProcessor
3838
- ).should == {
3839
- "rot13" => ["n", "o", "p"]
3840
- }
3841
- end
3842
-
3843
- it "should not map to anything when extracting values " +
3844
- "using the pattern " +
3845
- "'http://example.com/{-list|/|rot13}/'" do
3846
- @uri.extract_mapping("http://example.com/{-join|/|a,b,c}/").should == nil
3847
- end
3848
- end
3849
-
3850
- describe Addressable::URI, " when parsed from " +
3851
- "'http://example.com/?a=one&b=two&c=three'" do
3852
- before do
3853
- @uri = Addressable::URI.parse("http://example.com/?a=one&b=two&c=three")
3854
- end
3855
-
3856
- it "should have the correct mapping when extracting values " +
3857
- "using the pattern " +
3858
- "'http://example.com/?{-join|&|a,b,c}'" do
3859
- @uri.extract_mapping(
3860
- "http://example.com/?{-join|&|a,b,c}"
3861
- ).should == {
3862
- "a" => "one",
3863
- "b" => "two",
3864
- "c" => "three"
3865
- }
3866
- end
3867
- end
3868
-
3869
- describe Addressable::URI, " when parsed from " +
3870
- "'http://example.com/?rot13=frperg'" do
3871
- before do
3872
- @uri = Addressable::URI.parse("http://example.com/?rot13=frperg")
3873
- end
3874
-
3875
- it "should have the correct mapping when extracting values " +
3876
- "using the pattern " +
3877
- "'http://example.com/?{-join|&|rot13}' with the ExampleProcessor" do
3878
- @uri.extract_mapping(
3879
- "http://example.com/?{-join|&|rot13}",
3880
- ExampleProcessor
3881
- ).should == {
3882
- "rot13" => "secret"
3883
- }
3884
- end
3885
- end
3886
-
3887
- describe Addressable::URI, " when parsed from " +
3888
- "'http://example.com/one/spacer/two/'" do
3889
- before do
3890
- @uri = Addressable::URI.parse("http://example.com/one/spacer/two/")
3891
- end
3892
-
3893
- it "should have the correct mapping when extracting values " +
3894
- "using the pattern " +
3895
- "'http://example.com/{first}/spacer/{second}/'" do
3896
- @uri.extract_mapping(
3897
- "http://example.com/{first}/spacer/{second}/"
3898
- ).should == {
3899
- "first" => "one",
3900
- "second" => "two"
3901
- }
3902
- end
3903
-
3904
- it "should have the correct mapping when extracting values " +
3905
- "using the pattern " +
3906
- "'http://example.com{-prefix|/|stuff}/'" do
3907
- @uri.extract_mapping(
3908
- "http://example.com{-prefix|/|stuff}/"
3909
- ).should == {
3910
- "stuff" => ["one", "spacer", "two"]
3911
- }
3912
- end
3913
-
3914
- it "should have the correct mapping when extracting values " +
3915
- "using the pattern " +
3916
- "'http://example.com/o{-prefix|/|stuff}/'" do
3917
- @uri.extract_mapping(
3918
- "http://example.com/o{-prefix|/|stuff}/"
3919
- ).should == nil
3920
- end
3921
-
3922
- it "should have the correct mapping when extracting values " +
3923
- "using the pattern " +
3924
- "'http://example.com/{first}/spacer{-prefix|/|stuff}/'" do
3925
- @uri.extract_mapping(
3926
- "http://example.com/{first}/spacer{-prefix|/|stuff}/"
3927
- ).should == {
3928
- "first" => "one",
3929
- "stuff" => ["two"]
3930
- }
3931
- end
3932
-
3933
- it "should not match anything when extracting values " +
3934
- "using the incorrect suffix pattern " +
3935
- "'http://example.com/{-prefix|/|stuff}/'" do
3936
- @uri.extract_mapping(
3937
- "http://example.com/{-prefix|/|stuff}/"
3938
- ).should == nil
3939
- end
3940
-
3941
- it "should have the correct mapping when extracting values " +
3942
- "using the pattern " +
3943
- "'http://example.com{-prefix|/|rot13}/' with the ExampleProcessor" do
3944
- @uri.extract_mapping(
3945
- "http://example.com{-prefix|/|rot13}/",
3946
- ExampleProcessor
3947
- ).should == {
3948
- "rot13" => ["bar", "fcnpre", "gjb"]
3949
- }
3950
- end
3951
-
3952
- it "should have the correct mapping when extracting values " +
3953
- "using the pattern " +
3954
- "'http://example.com{-prefix|/|rot13}' with the ExampleProcessor" do
3955
- @uri.extract_mapping(
3956
- "http://example.com{-prefix|/|rot13}",
3957
- ExampleProcessor
3958
- ).should == {
3959
- "rot13" => ["bar", "fcnpre", "gjb", ""]
3960
- }
3961
- end
3962
-
3963
- it "should not match anything when extracting values " +
3964
- "using the incorrect suffix pattern " +
3965
- "'http://example.com/{-prefix|/|rot13}' with the ExampleProcessor" do
3966
- @uri.extract_mapping(
3967
- "http://example.com/{-prefix|/|rot13}",
3968
- ExampleProcessor
3969
- ).should == nil
3970
- end
3971
-
3972
- it "should have the correct mapping when extracting values " +
3973
- "using the pattern " +
3974
- "'http://example.com/{-suffix|/|stuff}'" do
3975
- @uri.extract_mapping(
3976
- "http://example.com/{-suffix|/|stuff}"
3977
- ).should == {
3978
- "stuff" => ["one", "spacer", "two"]
3979
- }
3980
- end
3981
-
3982
- it "should have the correct mapping when extracting values " +
3983
- "using the pattern " +
3984
- "'http://example.com/{-suffix|/|stuff}o'" do
3985
- @uri.extract_mapping(
3986
- "http://example.com/{-suffix|/|stuff}o"
3987
- ).should == nil
3988
- end
3989
-
3990
- it "should have the correct mapping when extracting values " +
3991
- "using the pattern " +
3992
- "'http://example.com/o{-suffix|/|stuff}'" do
3993
- @uri.extract_mapping(
3994
- "http://example.com/o{-suffix|/|stuff}"
3995
- ).should == {"stuff"=>["ne", "spacer", "two"]}
3996
- end
3997
-
3998
- it "should have the correct mapping when extracting values " +
3999
- "using the pattern " +
4000
- "'http://example.com/{first}/spacer/{-suffix|/|stuff}'" do
4001
- @uri.extract_mapping(
4002
- "http://example.com/{first}/spacer/{-suffix|/|stuff}"
4003
- ).should == {
4004
- "first" => "one",
4005
- "stuff" => ["two"]
4006
- }
4007
- end
4008
-
4009
- it "should not match anything when extracting values " +
4010
- "using the incorrect suffix pattern " +
4011
- "'http://example.com/{-suffix|/|stuff}/'" do
4012
- @uri.extract_mapping(
4013
- "http://example.com/{-suffix|/|stuff}/"
4014
- ).should == nil
4015
- end
4016
-
4017
- it "should have the correct mapping when extracting values " +
4018
- "using the pattern " +
4019
- "'http://example.com/{-suffix|/|rot13}' with the ExampleProcessor" do
4020
- @uri.extract_mapping(
4021
- "http://example.com/{-suffix|/|rot13}",
4022
- ExampleProcessor
4023
- ).should == {
4024
- "rot13" => ["bar", "fcnpre", "gjb"]
4025
- }
4026
- end
4027
-
4028
- it "should have the correct mapping when extracting values " +
4029
- "using the pattern " +
4030
- "'http://example.com{-suffix|/|rot13}' with the ExampleProcessor" do
4031
- @uri.extract_mapping(
4032
- "http://example.com{-suffix|/|rot13}",
4033
- ExampleProcessor
4034
- ).should == {
4035
- "rot13" => ["", "bar", "fcnpre", "gjb"]
4036
- }
4037
- end
4038
-
4039
- it "should not match anything when extracting values " +
4040
- "using the incorrect suffix pattern " +
4041
- "'http://example.com/{-suffix|/|rot13}/' with the ExampleProcessor" do
4042
- @uri.extract_mapping(
4043
- "http://example.com/{-suffix|/|rot13}/",
4044
- ExampleProcessor
4045
- ).should == nil
4046
- end
4047
- end
4048
-
4049
- describe Addressable::URI, " when parsed from " +
4050
- "'http://example.com/?email=bob@sporkmonger.com'" do
3346
+ describe Addressable::URI, "when given the input " +
3347
+ "'http://example.com/'" do
4051
3348
  before do
4052
- @uri = Addressable::URI.parse(
4053
- "http://example.com/?email=bob@sporkmonger.com"
4054
- )
4055
- end
4056
-
4057
- it "should not match anything when extracting values " +
4058
- "using the incorrect opt pattern " +
4059
- "'http://example.com/?email={-opt|bogus@bogus.com|test}'" do
4060
- @uri.extract_mapping(
4061
- "http://example.com/?email={-opt|bogus@bogus.com|test}"
4062
- ).should == nil
4063
- end
4064
-
4065
- it "should not match anything when extracting values " +
4066
- "using the incorrect neg pattern " +
4067
- "'http://example.com/?email={-neg|bogus@bogus.com|test}'" do
4068
- @uri.extract_mapping(
4069
- "http://example.com/?email={-neg|bogus@bogus.com|test}"
4070
- ).should == nil
4071
- end
4072
-
4073
- it "should indicate a match when extracting values " +
4074
- "using the opt pattern " +
4075
- "'http://example.com/?email={-opt|bob@sporkmonger.com|test}'" do
4076
- @uri.extract_mapping(
4077
- "http://example.com/?email={-opt|bob@sporkmonger.com|test}"
4078
- ).should == {}
3349
+ @input = "http://example.com/"
4079
3350
  end
4080
3351
 
4081
- it "should indicate a match when extracting values " +
4082
- "using the neg pattern " +
4083
- "'http://example.com/?email={-neg|bob@sporkmonger.com|test}'" do
4084
- @uri.extract_mapping(
4085
- "http://example.com/?email={-neg|bob@sporkmonger.com|test}"
4086
- ).should == {}
3352
+ it "should heuristically parse to 'http://example.com/'" do
3353
+ @uri = Addressable::URI.heuristic_parse(@input)
3354
+ @uri.to_s.should == "http://example.com/"
4087
3355
  end
4088
3356
  end
4089
3357
 
4090
- describe Addressable::URI, " when parsed from " +
4091
- "'http://example.com/?email='" do
4092
- before do
4093
- @uri = Addressable::URI.parse(
4094
- "http://example.com/?email="
4095
- )
4096
- end
4097
-
4098
- it "should indicate a match when extracting values " +
4099
- "using the opt pattern " +
4100
- "'http://example.com/?email={-opt|bob@sporkmonger.com|test}'" do
4101
- @uri.extract_mapping(
4102
- "http://example.com/?email={-opt|bob@sporkmonger.com|test}"
4103
- ).should == {}
4104
- end
4105
-
4106
- it "should indicate a match when extracting values " +
4107
- "using the neg pattern " +
4108
- "'http://example.com/?email={-neg|bob@sporkmonger.com|test}'" do
4109
- @uri.extract_mapping(
4110
- "http://example.com/?email={-neg|bob@sporkmonger.com|test}"
4111
- ).should == {}
4112
- end
4113
- end
4114
3358
 
4115
- describe Addressable::URI, " when parsed from " +
4116
- "'http://example.com/a/b/c/?one=1&two=2#foo'" do
3359
+ describe Addressable::URI, "when given the input " +
3360
+ "'http:example.com/'" do
4117
3361
  before do
4118
- @uri = Addressable::URI.parse(
4119
- "http://example.com/a/b/c/?one=1&two=2#foo"
4120
- )
3362
+ @input = "http:example.com/"
4121
3363
  end
4122
3364
 
4123
- it "should have the correct mapping when extracting values " +
4124
- "using the pattern " +
4125
- "'http://{host}/{-suffix|/|segments}?{-join|&|one,two}\#{fragment}'" do
4126
- @uri.extract_mapping(
4127
- "http://{host}/{-suffix|/|segments}?{-join|&|one,two}\#{fragment}"
4128
- ).should == {
4129
- "host" => "example.com",
4130
- "segments" => ["a", "b", "c"],
4131
- "one" => "1",
4132
- "two" => "2",
4133
- "fragment" => "foo"
4134
- }
3365
+ it "should heuristically parse to 'http://example.com/'" do
3366
+ @uri = Addressable::URI.heuristic_parse(@input)
3367
+ @uri.to_s.should == "http://example.com/"
4135
3368
  end
4136
3369
 
4137
- it "should not match when extracting values " +
4138
- "using the pattern " +
4139
- "'http://{host}/{-suffix|/|segments}?{-join|&|one}\#{fragment}'" do
4140
- @uri.extract_mapping(
4141
- "http://{host}/{-suffix|/|segments}?{-join|&|one}\#{fragment}"
4142
- ).should == nil
4143
- end
4144
-
4145
- it "should not match when extracting values " +
4146
- "using the pattern " +
4147
- "'http://{host}/{-suffix|/|segments}?{-join|&|bogus}\#{fragment}'" do
4148
- @uri.extract_mapping(
4149
- "http://{host}/{-suffix|/|segments}?{-join|&|bogus}\#{fragment}"
4150
- ).should == nil
4151
- end
4152
-
4153
- it "should not match when extracting values " +
4154
- "using the pattern " +
4155
- "'http://{host}/{-suffix|/|segments}?" +
4156
- "{-join|&|one,bogus}\#{fragment}'" do
4157
- @uri.extract_mapping(
4158
- "http://{host}/{-suffix|/|segments}?{-join|&|one,bogus}\#{fragment}"
4159
- ).should == nil
4160
- end
4161
-
4162
- it "should not match when extracting values " +
4163
- "using the pattern " +
4164
- "'http://{host}/{-suffix|/|segments}?" +
4165
- "{-join|&|one,two,bogus}\#{fragment}'" do
4166
- @uri.extract_mapping(
4167
- "http://{host}/{-suffix|/|segments}?{-join|&|one,two,bogus}\#{fragment}"
4168
- ).should == {
4169
- "host" => "example.com",
4170
- "segments" => ["a", "b", "c"],
4171
- "one" => "1",
4172
- "two" => "2",
4173
- "fragment" => "foo"
4174
- }
3370
+ it "should heuristically parse to 'http://example.com/' " +
3371
+ "even with a scheme hint of 'ftp'" do
3372
+ @uri = Addressable::URI.heuristic_parse(@input, {:scheme => 'ftp'})
3373
+ @uri.to_s.should == "http://example.com/"
4175
3374
  end
4176
3375
  end
4177
3376
 
4178
- describe Addressable::URI, "when given a pattern with bogus operators" do
3377
+ describe Addressable::URI, "when given the input " +
3378
+ "'http://example.com/example.com/'" do
4179
3379
  before do
4180
- @uri = Addressable::URI.parse("http://example.com/a/b/c/")
3380
+ @input = "http://example.com/example.com/"
4181
3381
  end
4182
3382
 
4183
- it "should raise an InvalidTemplateOperatorError" do
4184
- (lambda do
4185
- @uri.extract_mapping("http://example.com/{-bogus|/|a,b,c}/")
4186
- end).should raise_error(Addressable::URI::InvalidTemplateOperatorError)
4187
- end
4188
-
4189
- it "should raise an InvalidTemplateOperatorError" do
4190
- (lambda do
4191
- @uri.extract_mapping("http://example.com/{-prefix|/|a,b,c}/")
4192
- end).should raise_error(Addressable::URI::InvalidTemplateOperatorError)
4193
- end
4194
-
4195
- it "should raise an InvalidTemplateOperatorError" do
4196
- (lambda do
4197
- @uri.extract_mapping("http://example.com/{-suffix|/|a,b,c}/")
4198
- end).should raise_error(Addressable::URI::InvalidTemplateOperatorError)
4199
- end
4200
-
4201
- it "should raise an InvalidTemplateOperatorError" do
4202
- (lambda do
4203
- @uri.extract_mapping("http://example.com/{-list|/|a,b,c}/")
4204
- end).should raise_error(Addressable::URI::InvalidTemplateOperatorError)
3383
+ it "should heuristically parse to 'http://example.com/example.com/'" do
3384
+ @uri = Addressable::URI.heuristic_parse(@input)
3385
+ @uri.to_s.should == "http://example.com/example.com/"
4205
3386
  end
4206
3387
  end
4207
3388
 
4208
- describe Addressable::URI, " when given the input " +
3389
+ describe Addressable::URI, "when given the input " +
4209
3390
  "'/path/to/resource'" do
4210
3391
  before do
4211
3392
  @input = "/path/to/resource"
@@ -4217,7 +3398,7 @@ describe Addressable::URI, " when given the input " +
4217
3398
  end
4218
3399
  end
4219
3400
 
4220
- describe Addressable::URI, " when given the input " +
3401
+ describe Addressable::URI, "when given the input " +
4221
3402
  "'relative/path/to/resource'" do
4222
3403
  before do
4223
3404
  @input = "relative/path/to/resource"
@@ -4229,7 +3410,7 @@ describe Addressable::URI, " when given the input " +
4229
3410
  end
4230
3411
  end
4231
3412
 
4232
- describe Addressable::URI, " when given the input " +
3413
+ describe Addressable::URI, "when given the input " +
4233
3414
  "'example.com'" do
4234
3415
  before do
4235
3416
  @input = "example.com"
@@ -4241,7 +3422,7 @@ describe Addressable::URI, " when given the input " +
4241
3422
  end
4242
3423
  end
4243
3424
 
4244
- describe Addressable::URI, " when given the input " +
3425
+ describe Addressable::URI, "when given the input " +
4245
3426
  "'example.com' and a scheme hint of 'ftp'" do
4246
3427
  before do
4247
3428
  @input = "example.com"
@@ -4254,7 +3435,7 @@ describe Addressable::URI, " when given the input " +
4254
3435
  end
4255
3436
  end
4256
3437
 
4257
- describe Addressable::URI, " when given the input " +
3438
+ describe Addressable::URI, "when given the input " +
4258
3439
  "'example.com:21' and a scheme hint of 'ftp'" do
4259
3440
  before do
4260
3441
  @input = "example.com:21"
@@ -4267,7 +3448,7 @@ describe Addressable::URI, " when given the input " +
4267
3448
  end
4268
3449
  end
4269
3450
 
4270
- describe Addressable::URI, " when given the input " +
3451
+ describe Addressable::URI, "when given the input " +
4271
3452
  "'example.com/path/to/resource'" do
4272
3453
  before do
4273
3454
  @input = "example.com/path/to/resource"
@@ -4279,7 +3460,7 @@ describe Addressable::URI, " when given the input " +
4279
3460
  end
4280
3461
  end
4281
3462
 
4282
- describe Addressable::URI, " when given the input " +
3463
+ describe Addressable::URI, "when given the input " +
4283
3464
  "'http:///example.com'" do
4284
3465
  before do
4285
3466
  @input = "http:///example.com"
@@ -4291,7 +3472,7 @@ describe Addressable::URI, " when given the input " +
4291
3472
  end
4292
3473
  end
4293
3474
 
4294
- describe Addressable::URI, " when given the input " +
3475
+ describe Addressable::URI, "when given the input " +
4295
3476
  "'feed:///example.com'" do
4296
3477
  before do
4297
3478
  @input = "feed:///example.com"
@@ -4303,7 +3484,7 @@ describe Addressable::URI, " when given the input " +
4303
3484
  end
4304
3485
  end
4305
3486
 
4306
- describe Addressable::URI, " when given the input " +
3487
+ describe Addressable::URI, "when given the input " +
4307
3488
  "'file://path/to/resource/'" do
4308
3489
  before do
4309
3490
  @input = "file://path/to/resource/"
@@ -4315,7 +3496,7 @@ describe Addressable::URI, " when given the input " +
4315
3496
  end
4316
3497
  end
4317
3498
 
4318
- describe Addressable::URI, " when given the input " +
3499
+ describe Addressable::URI, "when given the input " +
4319
3500
  "'feed://http://example.com'" do
4320
3501
  before do
4321
3502
  @input = "feed://http://example.com"
@@ -4326,3 +3507,46 @@ describe Addressable::URI, " when given the input " +
4326
3507
  @uri.to_s.should == "feed:http://example.com"
4327
3508
  end
4328
3509
  end
3510
+
3511
+ describe Addressable::URI, "when assigning query values" do
3512
+ before do
3513
+ @uri = Addressable::URI.new
3514
+ end
3515
+
3516
+ it "should correctly assign {:a => 'a', :b => ['c', 'd', 'e']}" do
3517
+ @uri.query_values = {:a => "a", :b => ["c", "d", "e"]}
3518
+ @uri.query.should == "a=a&b[0]=c&b[1]=d&b[2]=e"
3519
+ end
3520
+
3521
+ it "should correctly assign " +
3522
+ "{:a => 'a', :b => [{:c => 'c', :d => 'd'}, {:e => 'e', :f => 'f'}]}" do
3523
+ @uri.query_values = {
3524
+ :a => "a", :b => [{:c => "c", :d => "d"}, {:e => "e", :f => "f"}]
3525
+ }
3526
+ @uri.query.should == "a=a&b[0][c]=c&b[0][d]=d&b[1][e]=e&b[1][f]=f"
3527
+ end
3528
+
3529
+ it "should correctly assign " +
3530
+ "{:a => 'a', :b => [{:c => true, :d => 'd'}, {:e => 'e', :f => 'f'}]}" do
3531
+ @uri.query_values = {
3532
+ :a => 'a', :b => [{:c => true, :d => 'd'}, {:e => 'e', :f => 'f'}]
3533
+ }
3534
+ @uri.query.should == "a=a&b[0][c]&b[0][d]=d&b[1][e]=e&b[1][f]=f"
3535
+ end
3536
+
3537
+ it "should correctly assign " +
3538
+ "{:a => 'a', :b => {:c => true, :d => 'd'}}" do
3539
+ @uri.query_values = {
3540
+ :a => 'a', :b => {:c => true, :d => 'd'}
3541
+ }
3542
+ @uri.query.should == "a=a&b[c]&b[d]=d"
3543
+ end
3544
+
3545
+ it "should correctly assign " +
3546
+ "{:a => 'a', :b => {:c => true, :d => 'd'}, :e => []}" do
3547
+ @uri.query_values = {
3548
+ :a => 'a', :b => {:c => true, :d => 'd'}
3549
+ }
3550
+ @uri.query.should == "a=a&b[c]&b[d]=d"
3551
+ end
3552
+ end