addressable 2.4.0 → 2.8.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,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # coding: utf-8
2
- # Copyright (C) 2006-2015 Bob Aman
4
+ # Copyright (C) Bob Aman
3
5
  #
4
6
  # Licensed under the Apache License, Version 2.0 (the "License");
5
7
  # you may not use this file except in compliance with the License.
@@ -63,124 +65,116 @@ end
63
65
 
64
66
  describe Addressable::URI, "when created with a non-numeric port number" do
65
67
  it "should raise an error" do
66
- expect(lambda do
68
+ expect do
67
69
  Addressable::URI.new(:port => "bogus")
68
- end).to raise_error(Addressable::URI::InvalidURIError)
70
+ end.to raise_error(Addressable::URI::InvalidURIError)
69
71
  end
70
72
  end
71
73
 
72
74
  describe Addressable::URI, "when created with a invalid encoded port number" do
73
75
  it "should raise an error" do
74
- expect(lambda do
76
+ expect do
75
77
  Addressable::URI.new(:port => "%eb")
76
- end).to raise_error(Addressable::URI::InvalidURIError)
78
+ end.to raise_error(Addressable::URI::InvalidURIError)
77
79
  end
78
80
  end
79
81
 
80
82
  describe Addressable::URI, "when created with a non-string scheme" do
81
83
  it "should raise an error" do
82
- expect(lambda do
84
+ expect do
83
85
  Addressable::URI.new(:scheme => :bogus)
84
- end).to raise_error(TypeError)
86
+ end.to raise_error(TypeError)
85
87
  end
86
88
  end
87
89
 
88
90
  describe Addressable::URI, "when created with a non-string user" do
89
91
  it "should raise an error" do
90
- expect(lambda do
92
+ expect do
91
93
  Addressable::URI.new(:user => :bogus)
92
- end).to raise_error(TypeError)
94
+ end.to raise_error(TypeError)
93
95
  end
94
96
  end
95
97
 
96
98
  describe Addressable::URI, "when created with a non-string password" do
97
99
  it "should raise an error" do
98
- expect(lambda do
100
+ expect do
99
101
  Addressable::URI.new(:password => :bogus)
100
- end).to raise_error(TypeError)
102
+ end.to raise_error(TypeError)
101
103
  end
102
104
  end
103
105
 
104
106
  describe Addressable::URI, "when created with a non-string userinfo" do
105
107
  it "should raise an error" do
106
- expect(lambda do
108
+ expect do
107
109
  Addressable::URI.new(:userinfo => :bogus)
108
- end).to raise_error(TypeError)
110
+ end.to raise_error(TypeError)
109
111
  end
110
112
  end
111
113
 
112
114
  describe Addressable::URI, "when created with a non-string host" do
113
115
  it "should raise an error" do
114
- expect(lambda do
116
+ expect do
115
117
  Addressable::URI.new(:host => :bogus)
116
- end).to raise_error(TypeError)
118
+ end.to raise_error(TypeError)
117
119
  end
118
120
  end
119
121
 
120
122
  describe Addressable::URI, "when created with a non-string authority" do
121
123
  it "should raise an error" do
122
- expect(lambda do
124
+ expect do
123
125
  Addressable::URI.new(:authority => :bogus)
124
- end).to raise_error(TypeError)
125
- end
126
- end
127
-
128
- describe Addressable::URI, "when created with a non-string authority" do
129
- it "should raise an error" do
130
- expect(lambda do
131
- Addressable::URI.new(:authority => :bogus)
132
- end).to raise_error(TypeError)
126
+ end.to raise_error(TypeError)
133
127
  end
134
128
  end
135
129
 
136
130
  describe Addressable::URI, "when created with a non-string path" do
137
131
  it "should raise an error" do
138
- expect(lambda do
132
+ expect do
139
133
  Addressable::URI.new(:path => :bogus)
140
- end).to raise_error(TypeError)
134
+ end.to raise_error(TypeError)
141
135
  end
142
136
  end
143
137
 
144
138
  describe Addressable::URI, "when created with a non-string query" do
145
139
  it "should raise an error" do
146
- expect(lambda do
140
+ expect do
147
141
  Addressable::URI.new(:query => :bogus)
148
- end).to raise_error(TypeError)
142
+ end.to raise_error(TypeError)
149
143
  end
150
144
  end
151
145
 
152
146
  describe Addressable::URI, "when created with a non-string fragment" do
153
147
  it "should raise an error" do
154
- expect(lambda do
148
+ expect do
155
149
  Addressable::URI.new(:fragment => :bogus)
156
- end).to raise_error(TypeError)
150
+ end.to raise_error(TypeError)
157
151
  end
158
152
  end
159
153
 
160
154
  describe Addressable::URI, "when created with a scheme but no hierarchical " +
161
155
  "segment" do
162
156
  it "should raise an error" do
163
- expect(lambda do
157
+ expect do
164
158
  Addressable::URI.parse("http:")
165
- end).to raise_error(Addressable::URI::InvalidURIError)
159
+ end.to raise_error(Addressable::URI::InvalidURIError)
166
160
  end
167
161
  end
168
162
 
169
163
  describe Addressable::URI, "quote handling" do
170
164
  describe 'in host name' do
171
165
  it "should raise an error for single quote" do
172
- expect(lambda do
166
+ expect do
173
167
  Addressable::URI.parse("http://local\"host/")
174
- end).to raise_error(Addressable::URI::InvalidURIError)
168
+ end.to raise_error(Addressable::URI::InvalidURIError)
175
169
  end
176
170
  end
177
171
  end
178
172
 
179
173
  describe Addressable::URI, "newline normalization" do
180
174
  it "should not accept newlines in scheme" do
181
- expect(lambda do
175
+ expect do
182
176
  Addressable::URI.parse("ht%0atp://localhost/")
183
- end).to raise_error(Addressable::URI::InvalidURIError)
177
+ end.to raise_error(Addressable::URI::InvalidURIError)
184
178
  end
185
179
 
186
180
  it "should not unescape newline in path" do
@@ -205,47 +199,47 @@ describe Addressable::URI, "newline normalization" do
205
199
 
206
200
  it "should not accept newline in hostname" do
207
201
  uri = Addressable::URI.parse("http://localhost/")
208
- expect(lambda do
202
+ expect do
209
203
  uri.host = "local\nhost"
210
- end).to raise_error(Addressable::URI::InvalidURIError)
204
+ end.to raise_error(Addressable::URI::InvalidURIError)
211
205
  end
212
206
  end
213
207
 
214
208
  describe Addressable::URI, "when created with ambiguous path" do
215
209
  it "should raise an error" do
216
- expect(lambda do
210
+ expect do
217
211
  Addressable::URI.parse("::http")
218
- end).to raise_error(Addressable::URI::InvalidURIError)
212
+ end.to raise_error(Addressable::URI::InvalidURIError)
219
213
  end
220
214
  end
221
215
 
222
216
  describe Addressable::URI, "when created with an invalid host" do
223
217
  it "should raise an error" do
224
- expect(lambda do
218
+ expect do
225
219
  Addressable::URI.new(:host => "<invalid>")
226
- end).to raise_error(Addressable::URI::InvalidURIError)
220
+ end.to raise_error(Addressable::URI::InvalidURIError)
227
221
  end
228
222
  end
229
223
 
230
224
  describe Addressable::URI, "when created with a host consisting of " +
231
225
  "sub-delims characters" do
232
226
  it "should not raise an error" do
233
- expect(lambda do
227
+ expect do
234
228
  Addressable::URI.new(
235
229
  :host => Addressable::URI::CharacterClasses::SUB_DELIMS.gsub(/\\/, '')
236
230
  )
237
- end).not_to raise_error
231
+ end.not_to raise_error
238
232
  end
239
233
  end
240
234
 
241
235
  describe Addressable::URI, "when created with a host consisting of " +
242
236
  "unreserved characters" do
243
237
  it "should not raise an error" do
244
- expect(lambda do
238
+ expect do
245
239
  Addressable::URI.new(
246
240
  :host => Addressable::URI::CharacterClasses::UNRESERVED.gsub(/\\/, '')
247
241
  )
248
- end).not_to raise_error
242
+ end.not_to raise_error
249
243
  end
250
244
  end
251
245
 
@@ -275,83 +269,83 @@ describe Addressable::URI, "when created from nil components" do
275
269
  end
276
270
 
277
271
  it "should raise an error if the scheme is set to whitespace" do
278
- expect(lambda do
272
+ expect do
279
273
  @uri.scheme = "\t \n"
280
- end).to raise_error(Addressable::URI::InvalidURIError)
274
+ end.to raise_error(Addressable::URI::InvalidURIError, /'\t \n'/)
281
275
  end
282
276
 
283
277
  it "should raise an error if the scheme is set to all digits" do
284
- expect(lambda do
278
+ expect do
285
279
  @uri.scheme = "123"
286
- end).to raise_error(Addressable::URI::InvalidURIError)
280
+ end.to raise_error(Addressable::URI::InvalidURIError, /'123'/)
287
281
  end
288
282
 
289
283
  it "should raise an error if the scheme begins with a digit" do
290
- expect(lambda do
284
+ expect do
291
285
  @uri.scheme = "1scheme"
292
- end).to raise_error(Addressable::URI::InvalidURIError)
286
+ end.to raise_error(Addressable::URI::InvalidURIError, /'1scheme'/)
293
287
  end
294
288
 
295
289
  it "should raise an error if the scheme begins with a plus" do
296
- expect(lambda do
290
+ expect do
297
291
  @uri.scheme = "+scheme"
298
- end).to raise_error(Addressable::URI::InvalidURIError)
292
+ end.to raise_error(Addressable::URI::InvalidURIError, /'\+scheme'/)
299
293
  end
300
294
 
301
295
  it "should raise an error if the scheme begins with a dot" do
302
- expect(lambda do
296
+ expect do
303
297
  @uri.scheme = ".scheme"
304
- end).to raise_error(Addressable::URI::InvalidURIError)
298
+ end.to raise_error(Addressable::URI::InvalidURIError, /'\.scheme'/)
305
299
  end
306
300
 
307
301
  it "should raise an error if the scheme begins with a dash" do
308
- expect(lambda do
302
+ expect do
309
303
  @uri.scheme = "-scheme"
310
- end).to raise_error(Addressable::URI::InvalidURIError)
304
+ end.to raise_error(Addressable::URI::InvalidURIError, /'-scheme'/)
311
305
  end
312
306
 
313
307
  it "should raise an error if the scheme contains an illegal character" do
314
- expect(lambda do
308
+ expect do
315
309
  @uri.scheme = "scheme!"
316
- end).to raise_error(Addressable::URI::InvalidURIError)
310
+ end.to raise_error(Addressable::URI::InvalidURIError, /'scheme!'/)
317
311
  end
318
312
 
319
313
  it "should raise an error if the scheme contains whitespace" do
320
- expect(lambda do
314
+ expect do
321
315
  @uri.scheme = "sch eme"
322
- end).to raise_error(Addressable::URI::InvalidURIError)
316
+ end.to raise_error(Addressable::URI::InvalidURIError, /'sch eme'/)
323
317
  end
324
318
 
325
319
  it "should raise an error if the scheme contains a newline" do
326
- expect(lambda do
320
+ expect do
327
321
  @uri.scheme = "sch\neme"
328
- end).to raise_error(Addressable::URI::InvalidURIError)
322
+ end.to raise_error(Addressable::URI::InvalidURIError)
329
323
  end
330
324
 
331
325
  it "should raise an error if set into an invalid state" do
332
- expect(lambda do
326
+ expect do
333
327
  @uri.user = "user"
334
- end).to raise_error(Addressable::URI::InvalidURIError)
328
+ end.to raise_error(Addressable::URI::InvalidURIError)
335
329
  end
336
330
 
337
331
  it "should raise an error if set into an invalid state" do
338
- expect(lambda do
332
+ expect do
339
333
  @uri.password = "pass"
340
- end).to raise_error(Addressable::URI::InvalidURIError)
334
+ end.to raise_error(Addressable::URI::InvalidURIError)
341
335
  end
342
336
 
343
337
  it "should raise an error if set into an invalid state" do
344
- expect(lambda do
338
+ expect do
345
339
  @uri.scheme = "http"
346
340
  @uri.fragment = "fragment"
347
- end).to raise_error(Addressable::URI::InvalidURIError)
341
+ end.to raise_error(Addressable::URI::InvalidURIError)
348
342
  end
349
343
 
350
344
  it "should raise an error if set into an invalid state" do
351
- expect(lambda do
345
+ expect do
352
346
  @uri.fragment = "fragment"
353
347
  @uri.scheme = "http"
354
- end).to raise_error(Addressable::URI::InvalidURIError)
348
+ end.to raise_error(Addressable::URI::InvalidURIError)
355
349
  end
356
350
  end
357
351
 
@@ -409,6 +403,10 @@ describe Addressable::URI, "when initialized from individual components" do
409
403
  expect(@uri.normalized_host).to eq("example.com")
410
404
  end
411
405
 
406
+ it "returns 'com' for #tld" do
407
+ expect(@uri.tld).to eq("com")
408
+ end
409
+
412
410
  it "returns 'user:password@example.com:8080' for #authority" do
413
411
  expect(@uri.authority).to eq("user:password@example.com:8080")
414
412
  end
@@ -959,6 +957,10 @@ describe Addressable::URI, "when frozen" do
959
957
  expect(@uri.normalize.query).to eq("a=1")
960
958
  end
961
959
 
960
+ it "returns '/%70a%74%68?a=%31' for #request_uri" do
961
+ expect(@uri.request_uri).to eq("/%70a%74%68?a=%31")
962
+ end
963
+
962
964
  it "returns '1%323' for #fragment" do
963
965
  expect(@uri.fragment).to eq("1%323")
964
966
  end
@@ -1013,31 +1015,31 @@ describe Addressable::URI, "when created from string components" do
1013
1015
  end
1014
1016
 
1015
1017
  it "should raise an error if invalid components omitted" do
1016
- expect(lambda do
1018
+ expect do
1017
1019
  @uri.omit(:bogus)
1018
- end).to raise_error(ArgumentError)
1019
- expect(lambda do
1020
+ end.to raise_error(ArgumentError)
1021
+ expect do
1020
1022
  @uri.omit(:scheme, :bogus, :path)
1021
- end).to raise_error(ArgumentError)
1023
+ end.to raise_error(ArgumentError)
1022
1024
  end
1023
1025
  end
1024
1026
 
1025
1027
  describe Addressable::URI, "when created with a nil host but " +
1026
1028
  "non-nil authority components" do
1027
1029
  it "should raise an error" do
1028
- expect(lambda do
1030
+ expect do
1029
1031
  Addressable::URI.new(:user => "user", :password => "pass", :port => 80)
1030
- end).to raise_error(Addressable::URI::InvalidURIError)
1032
+ end.to raise_error(Addressable::URI::InvalidURIError)
1031
1033
  end
1032
1034
  end
1033
1035
 
1034
1036
  describe Addressable::URI, "when created with both an authority and a user" do
1035
1037
  it "should raise an error" do
1036
- expect(lambda do
1038
+ expect do
1037
1039
  Addressable::URI.new(
1038
1040
  :user => "user", :authority => "user@example.com:80"
1039
1041
  )
1040
- end).to raise_error(ArgumentError)
1042
+ end.to raise_error(ArgumentError)
1041
1043
  end
1042
1044
  end
1043
1045
 
@@ -1073,11 +1075,35 @@ describe Addressable::URI, "when created with a host with trailing dots" do
1073
1075
  end
1074
1076
  end
1075
1077
 
1078
+ describe Addressable::URI, "when created with a host with a backslash" do
1079
+ it "should raise an error" do
1080
+ expect do
1081
+ Addressable::URI.new(:authority => "example\\example")
1082
+ end.to raise_error(Addressable::URI::InvalidURIError)
1083
+ end
1084
+ end
1085
+
1086
+ describe Addressable::URI, "when created with a host with a slash" do
1087
+ it "should raise an error" do
1088
+ expect do
1089
+ Addressable::URI.new(:authority => "example/example")
1090
+ end.to raise_error(Addressable::URI::InvalidURIError)
1091
+ end
1092
+ end
1093
+
1094
+ describe Addressable::URI, "when created with a host with a space" do
1095
+ it "should raise an error" do
1096
+ expect do
1097
+ Addressable::URI.new(:authority => "example example")
1098
+ end.to raise_error(Addressable::URI::InvalidURIError)
1099
+ end
1100
+ end
1101
+
1076
1102
  describe Addressable::URI, "when created with both a userinfo and a user" do
1077
1103
  it "should raise an error" do
1078
- expect(lambda do
1104
+ expect do
1079
1105
  Addressable::URI.new(:user => "user", :userinfo => "user:pass")
1080
- end).to raise_error(ArgumentError)
1106
+ end.to raise_error(ArgumentError)
1081
1107
  end
1082
1108
  end
1083
1109
 
@@ -1169,18 +1195,18 @@ describe Addressable::URI, "when parsed from something that looks " +
1169
1195
  "like a URI object" do
1170
1196
  it "should parse without error" do
1171
1197
  uri = Addressable::URI.parse(Fake::URI::HTTP.new("http://example.com/"))
1172
- expect(lambda do
1198
+ expect do
1173
1199
  Addressable::URI.parse(uri)
1174
- end).not_to raise_error
1200
+ end.not_to raise_error
1175
1201
  end
1176
1202
  end
1177
1203
 
1178
1204
  describe Addressable::URI, "when parsed from a standard library URI object" do
1179
1205
  it "should parse without error" do
1180
1206
  uri = Addressable::URI.parse(URI.parse("http://example.com/"))
1181
- expect(lambda do
1207
+ expect do
1182
1208
  Addressable::URI.parse(uri)
1183
- end).not_to raise_error
1209
+ end.not_to raise_error
1184
1210
  end
1185
1211
  end
1186
1212
 
@@ -1340,9 +1366,9 @@ describe Addressable::URI, "when parsed from " +
1340
1366
  end
1341
1367
 
1342
1368
  it "should not allow request URI assignment" do
1343
- expect(lambda do
1369
+ expect do
1344
1370
  @uri.request_uri = "/"
1345
- end).to raise_error(Addressable::URI::InvalidURIError)
1371
+ end.to raise_error(Addressable::URI::InvalidURIError)
1346
1372
  end
1347
1373
 
1348
1374
  it "should have a query of 'objectClass?one'" do
@@ -1364,9 +1390,9 @@ describe Addressable::URI, "when parsed from " +
1364
1390
  end
1365
1391
 
1366
1392
  it "should raise an error if omission would create an invalid URI" do
1367
- expect(lambda do
1393
+ expect do
1368
1394
  @uri.omit(:authority, :path)
1369
- end).to raise_error(Addressable::URI::InvalidURIError)
1395
+ end.to raise_error(Addressable::URI::InvalidURIError)
1370
1396
  end
1371
1397
 
1372
1398
  it "should have an origin of 'ldap://[2001:db8::7]'" do
@@ -1752,9 +1778,9 @@ describe Addressable::URI, "when parsed from " +
1752
1778
 
1753
1779
  it "should not be roughly equal to the string " +
1754
1780
  "'http://example.com:bogus/'" do
1755
- expect(lambda do
1781
+ expect do
1756
1782
  expect(@uri === "http://example.com:bogus/").to eq(false)
1757
- end).not_to raise_error
1783
+ end.not_to raise_error
1758
1784
  end
1759
1785
 
1760
1786
  it "should result in itself when joined with itself" do
@@ -1775,7 +1801,7 @@ describe Addressable::URI, "when parsed from " +
1775
1801
  end
1776
1802
 
1777
1803
  it "should have the same hash as http://EXAMPLE.com after assignment" do
1778
- @uri.host = "EXAMPLE.com"
1804
+ @uri.origin = "http://EXAMPLE.com"
1779
1805
  expect(@uri.hash).to eq(Addressable::URI.parse("http://EXAMPLE.com").hash)
1780
1806
  end
1781
1807
 
@@ -1783,6 +1809,24 @@ describe Addressable::URI, "when parsed from " +
1783
1809
  expect(@uri.hash).not_to eq(Addressable::URI.parse("http://EXAMPLE.com").hash)
1784
1810
  end
1785
1811
 
1812
+ it "should not allow origin assignment without scheme" do
1813
+ expect do
1814
+ @uri.origin = "example.com"
1815
+ end.to raise_error(Addressable::URI::InvalidURIError)
1816
+ end
1817
+
1818
+ it "should not allow origin assignment without host" do
1819
+ expect do
1820
+ @uri.origin = "http://"
1821
+ end.to raise_error(Addressable::URI::InvalidURIError)
1822
+ end
1823
+
1824
+ it "should not allow origin assignment with bogus type" do
1825
+ expect do
1826
+ @uri.origin = :bogus
1827
+ end.to raise_error(TypeError)
1828
+ end
1829
+
1786
1830
  # Section 6.2.3 of RFC 3986
1787
1831
  it "should be equivalent to http://example.com/" do
1788
1832
  expect(@uri).to eq(Addressable::URI.parse("http://example.com/"))
@@ -1836,9 +1880,9 @@ describe Addressable::URI, "when parsed from " +
1836
1880
  end
1837
1881
 
1838
1882
  it "when joined with a bogus object a TypeError should be raised" do
1839
- expect(lambda do
1883
+ expect do
1840
1884
  @uri.join(42)
1841
- end).to raise_error(TypeError)
1885
+ end.to raise_error(TypeError)
1842
1886
  end
1843
1887
 
1844
1888
  it "should have the correct username after assignment" do
@@ -1933,15 +1977,29 @@ end
1933
1977
 
1934
1978
  # Section 5.1.2 of RFC 2616
1935
1979
  describe Addressable::URI, "when parsed from " +
1936
- "'http://www.w3.org/pub/WWW/TheProject.html'" do
1980
+ "'HTTP://www.w3.org/pub/WWW/TheProject.html'" do
1937
1981
  before do
1938
- @uri = Addressable::URI.parse("http://www.w3.org/pub/WWW/TheProject.html")
1982
+ @uri = Addressable::URI.parse("HTTP://www.w3.org/pub/WWW/TheProject.html")
1939
1983
  end
1940
1984
 
1941
1985
  it "should have the correct request URI" do
1942
1986
  expect(@uri.request_uri).to eq("/pub/WWW/TheProject.html")
1943
1987
  end
1944
1988
 
1989
+ it "should have the correct request URI after assignment" do
1990
+ @uri.request_uri = "/pub/WWW/TheProject.html?"
1991
+ expect(@uri.request_uri).to eq("/pub/WWW/TheProject.html?")
1992
+ expect(@uri.path).to eq("/pub/WWW/TheProject.html")
1993
+ expect(@uri.query).to eq("")
1994
+ end
1995
+
1996
+ it "should have the correct request URI after assignment" do
1997
+ @uri.request_uri = "/some/where/else.html"
1998
+ expect(@uri.request_uri).to eq("/some/where/else.html")
1999
+ expect(@uri.path).to eq("/some/where/else.html")
2000
+ expect(@uri.query).to eq(nil)
2001
+ end
2002
+
1945
2003
  it "should have the correct request URI after assignment" do
1946
2004
  @uri.request_uri = "/some/where/else.html?query?string"
1947
2005
  expect(@uri.request_uri).to eq("/some/where/else.html?query?string")
@@ -1957,20 +2015,20 @@ describe Addressable::URI, "when parsed from " +
1957
2015
  end
1958
2016
 
1959
2017
  it "should raise an error if the site value is set to something bogus" do
1960
- expect(lambda do
2018
+ expect do
1961
2019
  @uri.site = 42
1962
- end).to raise_error(TypeError)
2020
+ end.to raise_error(TypeError)
1963
2021
  end
1964
2022
 
1965
2023
  it "should raise an error if the request URI is set to something bogus" do
1966
- expect(lambda do
2024
+ expect do
1967
2025
  @uri.request_uri = 42
1968
- end).to raise_error(TypeError)
2026
+ end.to raise_error(TypeError)
1969
2027
  end
1970
2028
 
1971
2029
  it "should correctly convert to a hash" do
1972
2030
  expect(@uri.to_hash).to eq({
1973
- :scheme => "http",
2031
+ :scheme => "HTTP",
1974
2032
  :user => nil,
1975
2033
  :password => nil,
1976
2034
  :host => "www.w3.org",
@@ -2014,9 +2072,9 @@ describe Addressable::URI, "when parsing IPv6 addresses" do
2014
2072
 
2015
2073
  it "should raise an error for " +
2016
2074
  "'http://[<invalid>]/'" do
2017
- expect(lambda do
2075
+ expect do
2018
2076
  Addressable::URI.parse("http://[<invalid>]/")
2019
- end).to raise_error(Addressable::URI::InvalidURIError)
2077
+ end.to raise_error(Addressable::URI::InvalidURIError)
2020
2078
  end
2021
2079
  end
2022
2080
 
@@ -2042,9 +2100,9 @@ describe Addressable::URI, "when assigning IPv6 address" do
2042
2100
  it "should not allow to set bare IPv6 address as host" do
2043
2101
  uri = Addressable::URI.parse("http://[::1]/")
2044
2102
  skip "not checked"
2045
- expect(lambda do
2103
+ expect do
2046
2104
  uri.host = '3ffe:1900:4545:3:200:f8ff:fe21:67cf'
2047
- end).to raise_error(Addressable::URI::InvalidURIError)
2105
+ end.to raise_error(Addressable::URI::InvalidURIError)
2048
2106
  end
2049
2107
  end
2050
2108
 
@@ -2076,9 +2134,9 @@ describe Addressable::URI, "when parsing IPvFuture addresses" do
2076
2134
 
2077
2135
  it "should raise an error for " +
2078
2136
  "'http://[v0.<invalid>]/'" do
2079
- expect(lambda do
2137
+ expect do
2080
2138
  Addressable::URI.parse("http://[v0.<invalid>]/")
2081
- end).to raise_error(Addressable::URI::InvalidURIError)
2139
+ end.to raise_error(Addressable::URI::InvalidURIError)
2082
2140
  end
2083
2141
  end
2084
2142
 
@@ -2320,6 +2378,80 @@ describe Addressable::URI, "when parsed from " +
2320
2378
  end
2321
2379
  end
2322
2380
 
2381
+ describe Addressable::URI, "when parsed from " +
2382
+ "'HTTP://EXAMPLE.COM/'" do
2383
+ before do
2384
+ @uri = Addressable::URI.parse("HTTP://EXAMPLE.COM/")
2385
+ end
2386
+
2387
+ it "should be equivalent to http://example.com" do
2388
+ expect(@uri).to eq(Addressable::URI.parse("http://example.com"))
2389
+ end
2390
+
2391
+ it "should correctly convert to a hash" do
2392
+ expect(@uri.to_hash).to eq({
2393
+ :scheme => "HTTP",
2394
+ :user => nil,
2395
+ :password => nil,
2396
+ :host => "EXAMPLE.COM",
2397
+ :port => nil,
2398
+ :path => "/",
2399
+ :query => nil,
2400
+ :fragment => nil
2401
+ })
2402
+ end
2403
+
2404
+ it "should be identical to its duplicate" do
2405
+ expect(@uri).to eq(@uri.dup)
2406
+ end
2407
+
2408
+ it "should have an origin of 'http://example.com'" do
2409
+ expect(@uri.origin).to eq('http://example.com')
2410
+ end
2411
+
2412
+ it "should have a tld of 'com'" do
2413
+ expect(@uri.tld).to eq('com')
2414
+ end
2415
+ end
2416
+
2417
+ describe Addressable::URI, "when parsed from " +
2418
+ "'http://www.example.co.uk/'" do
2419
+ before do
2420
+ @uri = Addressable::URI.parse("http://www.example.co.uk/")
2421
+ end
2422
+
2423
+ it "should have an origin of 'http://www.example.co.uk'" do
2424
+ expect(@uri.origin).to eq('http://www.example.co.uk')
2425
+ end
2426
+
2427
+ it "should have a tld of 'co.uk'" do
2428
+ expect(@uri.tld).to eq('co.uk')
2429
+ end
2430
+
2431
+ it "should have a domain of 'example.co.uk'" do
2432
+ expect(@uri.domain).to eq('example.co.uk')
2433
+ end
2434
+ end
2435
+
2436
+ describe Addressable::URI, "when parsed from " +
2437
+ "'http://sub_domain.blogspot.com/'" do
2438
+ before do
2439
+ @uri = Addressable::URI.parse("http://sub_domain.blogspot.com/")
2440
+ end
2441
+
2442
+ it "should have an origin of 'http://sub_domain.blogspot.com'" do
2443
+ expect(@uri.origin).to eq('http://sub_domain.blogspot.com')
2444
+ end
2445
+
2446
+ it "should have a tld of 'com'" do
2447
+ expect(@uri.tld).to eq('com')
2448
+ end
2449
+
2450
+ it "should have a domain of 'blogspot.com'" do
2451
+ expect(@uri.domain).to eq('blogspot.com')
2452
+ end
2453
+ end
2454
+
2323
2455
  describe Addressable::URI, "when parsed from " +
2324
2456
  "'http://example.com/~smith/'" do
2325
2457
  before do
@@ -2348,9 +2480,9 @@ describe Addressable::URI, "when parsed from " +
2348
2480
  end
2349
2481
 
2350
2482
  it "should not raise an exception when normalized" do
2351
- expect(lambda do
2483
+ expect do
2352
2484
  @uri.normalize
2353
- end).not_to raise_error
2485
+ end.not_to raise_error
2354
2486
  end
2355
2487
 
2356
2488
  it "should be considered to be in normal form" do
@@ -2402,9 +2534,9 @@ describe Addressable::URI, "when parsed from " +
2402
2534
  end
2403
2535
 
2404
2536
  it "should not raise an exception when normalized" do
2405
- expect(lambda do
2537
+ expect do
2406
2538
  @uri.normalize
2407
- end).not_to raise_error
2539
+ end.not_to raise_error
2408
2540
  end
2409
2541
 
2410
2542
  it "should be considered to be in normal form" do
@@ -2427,9 +2559,9 @@ describe Addressable::URI, "when parsed from " +
2427
2559
  end
2428
2560
 
2429
2561
  it "should not raise an exception when normalized" do
2430
- expect(lambda do
2562
+ expect do
2431
2563
  @uri.normalize
2432
- end).not_to raise_error
2564
+ end.not_to raise_error
2433
2565
  end
2434
2566
 
2435
2567
  it "should be considered to be in normal form" do
@@ -2465,9 +2597,9 @@ describe Addressable::URI, "when parsed from " +
2465
2597
  end
2466
2598
 
2467
2599
  it "should raise an error if encoding with an unexpected return type" do
2468
- expect(lambda do
2600
+ expect do
2469
2601
  Addressable::URI.normalized_encode(@uri, Integer)
2470
- end).to raise_error(TypeError)
2602
+ end.to raise_error(TypeError)
2471
2603
  end
2472
2604
 
2473
2605
  it "if percent encoded should be 'http://example.com/C%25CC%25A7'" do
@@ -2483,9 +2615,9 @@ describe Addressable::URI, "when parsed from " +
2483
2615
  end
2484
2616
 
2485
2617
  it "should raise an error if encoding with an unexpected return type" do
2486
- expect(lambda do
2618
+ expect do
2487
2619
  Addressable::URI.encode(@uri, Integer)
2488
- end).to raise_error(TypeError)
2620
+ end.to raise_error(TypeError)
2489
2621
  end
2490
2622
 
2491
2623
  it "should be identical to its duplicate" do
@@ -2620,9 +2752,9 @@ describe Addressable::URI, "when parsed from " +
2620
2752
 
2621
2753
  it "should not be roughly equal to the string " +
2622
2754
  "'http://example.com:bogus/'" do
2623
- expect(lambda do
2755
+ expect do
2624
2756
  expect(@uri === "http://example.com:bogus/").to eq(false)
2625
- end).not_to raise_error
2757
+ end.not_to raise_error
2626
2758
  end
2627
2759
 
2628
2760
  it "should result in itself when joined with itself" do
@@ -2961,6 +3093,23 @@ describe Addressable::URI, "when parsed from " +
2961
3093
  end
2962
3094
  end
2963
3095
 
3096
+ describe Addressable::URI, "when parsed from " +
3097
+ "'/..//example.com'" do
3098
+ before do
3099
+ @uri = Addressable::URI.parse("/..//example.com")
3100
+ end
3101
+
3102
+ it "should become invalid when normalized" do
3103
+ expect do
3104
+ @uri.normalize
3105
+ end.to raise_error(Addressable::URI::InvalidURIError, /authority/)
3106
+ end
3107
+
3108
+ it "should have a path of '/..//example.com'" do
3109
+ expect(@uri.path).to eq("/..//example.com")
3110
+ end
3111
+ end
3112
+
2964
3113
  describe Addressable::URI, "when parsed from '/a/b/c/./../../g'" do
2965
3114
  before do
2966
3115
  @uri = Addressable::URI.parse("/a/b/c/./../../g")
@@ -3191,12 +3340,12 @@ describe Addressable::URI, "when parsed from " +
3191
3340
  end
3192
3341
 
3193
3342
  it "should raise an error if routing is attempted" do
3194
- expect(lambda do
3343
+ expect do
3195
3344
  @uri.route_to("http://example.com/")
3196
- end).to raise_error(ArgumentError, /relative\/path\/to\/resource/)
3197
- expect(lambda do
3345
+ end.to raise_error(ArgumentError, /relative\/path\/to\/resource/)
3346
+ expect do
3198
3347
  @uri.route_from("http://example.com/")
3199
- end).to raise_error(ArgumentError, /relative\/path\/to\/resource/)
3348
+ end.to raise_error(ArgumentError, /relative\/path\/to\/resource/)
3200
3349
  end
3201
3350
 
3202
3351
  it "when joined with 'another/relative/path' should be " +
@@ -3793,9 +3942,9 @@ describe Addressable::URI, "when parsed from " +
3793
3942
  end
3794
3943
 
3795
3944
  it "should raise an error if assigning a bogus object to the hostname" do
3796
- expect(lambda do
3945
+ expect do
3797
3946
  @uri.hostname = Object.new
3798
- end).to raise_error
3947
+ end.to raise_error(TypeError)
3799
3948
  end
3800
3949
 
3801
3950
  it "should have the correct port after assignment" do
@@ -3874,9 +4023,9 @@ describe Addressable::URI, "when parsed from " +
3874
4023
  end
3875
4024
 
3876
4025
  it "should raise an error if query values are set to a bogus type" do
3877
- expect(lambda do
4026
+ expect do
3878
4027
  @uri.query_values = "bogus"
3879
- end).to raise_error(TypeError)
4028
+ end.to raise_error(TypeError)
3880
4029
  end
3881
4030
 
3882
4031
  it "should have the correct fragment after assignment" do
@@ -3948,39 +4097,39 @@ describe Addressable::URI, "when parsed from " +
3948
4097
  end
3949
4098
 
3950
4099
  it "should fail to merge with bogus values" do
3951
- expect(lambda do
4100
+ expect do
3952
4101
  @uri.merge(:port => "bogus")
3953
- end).to raise_error(Addressable::URI::InvalidURIError)
4102
+ end.to raise_error(Addressable::URI::InvalidURIError)
3954
4103
  end
3955
4104
 
3956
4105
  it "should fail to merge with bogus values" do
3957
- expect(lambda do
4106
+ expect do
3958
4107
  @uri.merge(:authority => "bar@baz:bogus")
3959
- end).to raise_error(Addressable::URI::InvalidURIError)
4108
+ end.to raise_error(Addressable::URI::InvalidURIError)
3960
4109
  end
3961
4110
 
3962
4111
  it "should fail to merge with bogus parameters" do
3963
- expect(lambda do
4112
+ expect do
3964
4113
  @uri.merge(42)
3965
- end).to raise_error(TypeError)
4114
+ end.to raise_error(TypeError)
3966
4115
  end
3967
4116
 
3968
4117
  it "should fail to merge with bogus parameters" do
3969
- expect(lambda do
4118
+ expect do
3970
4119
  @uri.merge("http://example.com/")
3971
- end).to raise_error(TypeError)
4120
+ end.to raise_error(TypeError)
3972
4121
  end
3973
4122
 
3974
4123
  it "should fail to merge with both authority and subcomponents" do
3975
- expect(lambda do
4124
+ expect do
3976
4125
  @uri.merge(:authority => "foo:bar@baz:42", :port => "42")
3977
- end).to raise_error(ArgumentError)
4126
+ end.to raise_error(ArgumentError)
3978
4127
  end
3979
4128
 
3980
4129
  it "should fail to merge with both userinfo and subcomponents" do
3981
- expect(lambda do
4130
+ expect do
3982
4131
  @uri.merge(:userinfo => "foo:bar", :user => "foo")
3983
- end).to raise_error(ArgumentError)
4132
+ end.to raise_error(ArgumentError)
3984
4133
  end
3985
4134
 
3986
4135
  it "should be identical to its duplicate" do
@@ -4113,6 +4262,36 @@ describe Addressable::URI, "when parsed from " +
4113
4262
  end
4114
4263
  end
4115
4264
 
4265
+ describe Addressable::URI, "when parsed from 'https://example.com/?q=a+b'" do
4266
+ before do
4267
+ @uri = Addressable::URI.parse("https://example.com/?q=a+b")
4268
+ end
4269
+
4270
+ it "should have query_values of {'q' => 'a b'}" do
4271
+ expect(@uri.query_values).to eq("q" => "a b")
4272
+ end
4273
+ end
4274
+
4275
+ describe Addressable::URI, "when parsed from 'example.com?q=a+b'" do
4276
+ before do
4277
+ @uri = Addressable::URI.parse("example.com?q=a+b")
4278
+ end
4279
+
4280
+ it "should have query_values of {'q' => 'a b'}" do
4281
+ expect(@uri.query_values).to eq("q" => "a b")
4282
+ end
4283
+ end
4284
+
4285
+ describe Addressable::URI, "when parsed from 'mailto:?q=a+b'" do
4286
+ before do
4287
+ @uri = Addressable::URI.parse("mailto:?q=a+b")
4288
+ end
4289
+
4290
+ it "should have query_values of {'q' => 'a+b'}" do
4291
+ expect(@uri.query_values).to eq("q" => "a+b")
4292
+ end
4293
+ end
4294
+
4116
4295
  describe Addressable::URI, "when parsed from " +
4117
4296
  "'http://example.com/?q=a%2bb'" do
4118
4297
  before do
@@ -4154,6 +4333,46 @@ describe Addressable::URI, "when parsed from " +
4154
4333
  end
4155
4334
  end
4156
4335
 
4336
+ describe Addressable::URI, "when parsed from 'http://example/?b=1&a=2&c=3'" do
4337
+ before do
4338
+ @uri = Addressable::URI.parse("http://example/?b=1&a=2&c=3")
4339
+ end
4340
+
4341
+ it "should have a sorted normalized query of 'a=2&b=1&c=3'" do
4342
+ expect(@uri.normalized_query(:sorted)).to eq("a=2&b=1&c=3")
4343
+ end
4344
+ end
4345
+
4346
+ describe Addressable::URI, "when parsed from 'http://example/?&a&&c&'" do
4347
+ before do
4348
+ @uri = Addressable::URI.parse("http://example/?&a&&c&")
4349
+ end
4350
+
4351
+ it "should have a compacted normalized query of 'a&c'" do
4352
+ expect(@uri.normalized_query(:compacted)).to eq("a&c")
4353
+ end
4354
+ end
4355
+
4356
+ describe Addressable::URI, "when parsed from 'http://example.com/?a=1&a=1'" do
4357
+ before do
4358
+ @uri = Addressable::URI.parse("http://example.com/?a=1&a=1")
4359
+ end
4360
+
4361
+ it "should have a compacted normalized query of 'a=1'" do
4362
+ expect(@uri.normalized_query(:compacted)).to eq("a=1")
4363
+ end
4364
+ end
4365
+
4366
+ describe Addressable::URI, "when parsed from 'http://example.com/?a=1&a=2'" do
4367
+ before do
4368
+ @uri = Addressable::URI.parse("http://example.com/?a=1&a=2")
4369
+ end
4370
+
4371
+ it "should have a compacted normalized query of 'a=1&a=2'" do
4372
+ expect(@uri.normalized_query(:compacted)).to eq("a=1&a=2")
4373
+ end
4374
+ end
4375
+
4157
4376
  describe Addressable::URI, "when parsed from " +
4158
4377
  "'http://example.com/sound%2bvision'" do
4159
4378
  before do
@@ -4265,10 +4484,10 @@ describe Addressable::URI, "when parsed from " +
4265
4484
  end
4266
4485
 
4267
4486
  it "should raise an error after nil assignment of authority segment" do
4268
- expect(lambda do
4487
+ expect do
4269
4488
  # This would create an invalid URI
4270
4489
  @uri.authority = nil
4271
- end).to raise_error
4490
+ end.to raise_error(Addressable::URI::InvalidURIError)
4272
4491
  end
4273
4492
  end
4274
4493
 
@@ -4497,12 +4716,12 @@ describe Addressable::URI, "when parsed from " +
4497
4716
  end
4498
4717
 
4499
4718
  it "should raise an error if routing is attempted" do
4500
- expect(lambda do
4719
+ expect do
4501
4720
  @uri.route_to("http://example.com/")
4502
- end).to raise_error(ArgumentError, /\/\/example.com\//)
4503
- expect(lambda do
4721
+ end.to raise_error(ArgumentError, /\/\/example.com\//)
4722
+ expect do
4504
4723
  @uri.route_from("http://example.com/")
4505
- end).to raise_error(ArgumentError, /\/\/example.com\//)
4724
+ end.to raise_error(ArgumentError, /\/\/example.com\//)
4506
4725
  end
4507
4726
 
4508
4727
  it "should have a 'null' origin" do
@@ -4596,9 +4815,9 @@ end
4596
4815
  describe Addressable::URI, "when parsed from " +
4597
4816
  "'http://under_score.example.com/'" do
4598
4817
  it "should not cause an error" do
4599
- expect(lambda do
4818
+ expect do
4600
4819
  Addressable::URI.parse("http://under_score.example.com/")
4601
- end).not_to raise_error
4820
+ end.not_to raise_error
4602
4821
  end
4603
4822
  end
4604
4823
 
@@ -4670,9 +4889,9 @@ describe Addressable::URI, "when parsed from '?one=1&two=2&three=3'" do
4670
4889
  end
4671
4890
 
4672
4891
  it "should raise an error for invalid return type values" do
4673
- expect(lambda do
4674
- @uri.query_values(Fixnum)
4675
- end).to raise_error(ArgumentError)
4892
+ expect do
4893
+ @uri.query_values(Integer)
4894
+ end.to raise_error(ArgumentError)
4676
4895
  end
4677
4896
 
4678
4897
  it "should have the correct array query values" do
@@ -5273,9 +5492,9 @@ describe Addressable::URI, "with a base uri of 'http://a/b/c/d;p?q'" do
5273
5492
  end
5274
5493
 
5275
5494
  it "when joined with a bogus object a TypeError should be raised" do
5276
- expect(lambda do
5495
+ expect do
5277
5496
  Addressable::URI.join(@uri, 42)
5278
- end).to raise_error(TypeError)
5497
+ end.to raise_error(TypeError)
5279
5498
  end
5280
5499
  end
5281
5500
 
@@ -5302,9 +5521,9 @@ end
5302
5521
 
5303
5522
  describe Addressable::URI, "when converting a bogus path" do
5304
5523
  it "should raise a TypeError" do
5305
- expect(lambda do
5524
+ expect do
5306
5525
  Addressable::URI.convert_path(42)
5307
- end).to raise_error(TypeError)
5526
+ end.to raise_error(TypeError)
5308
5527
  end
5309
5528
  end
5310
5529
 
@@ -5357,6 +5576,31 @@ describe Addressable::URI, "when given the path '/one/two/'" do
5357
5576
  end
5358
5577
  end
5359
5578
 
5579
+ describe Addressable::URI, "when given the tld " do
5580
+ it "'uk' should have a tld of 'uk'" do
5581
+ uri = Addressable::URI.parse("http://example.com")
5582
+ uri.tld = "uk"
5583
+
5584
+ expect(uri.tld).to eq("uk")
5585
+ end
5586
+
5587
+ context "which " do
5588
+ let (:uri) { Addressable::URI.parse("http://www.comrade.net/path/to/source/") }
5589
+
5590
+ it "contains a subdomain" do
5591
+ uri.tld = "co.uk"
5592
+
5593
+ expect(uri.to_s).to eq("http://www.comrade.co.uk/path/to/source/")
5594
+ end
5595
+
5596
+ it "is part of the domain" do
5597
+ uri.tld = "com"
5598
+
5599
+ expect(uri.to_s).to eq("http://www.comrade.com/path/to/source/")
5600
+ end
5601
+ end
5602
+ end
5603
+
5360
5604
  describe Addressable::URI, "when given the path " +
5361
5605
  "'c:\\windows\\My Documents 100%20\\foo.txt'" do
5362
5606
  before do
@@ -5474,9 +5718,9 @@ describe Addressable::URI, "when parsing a non-String object" do
5474
5718
  end
5475
5719
 
5476
5720
  it "should raise a TypeError for objects than cannot be converted" do
5477
- expect(lambda do
5721
+ expect do
5478
5722
  Addressable::URI.parse(42)
5479
- end).to raise_error(TypeError, "Can't convert Fixnum into String.")
5723
+ end.to raise_error(TypeError)
5480
5724
  end
5481
5725
 
5482
5726
  it "should correctly parse heuristically anything with a 'to_str' method" do
@@ -5484,9 +5728,9 @@ describe Addressable::URI, "when parsing a non-String object" do
5484
5728
  end
5485
5729
 
5486
5730
  it "should raise a TypeError for objects than cannot be converted" do
5487
- expect(lambda do
5731
+ expect do
5488
5732
  Addressable::URI.heuristic_parse(42)
5489
- end).to raise_error(TypeError, "Can't convert Fixnum into String.")
5733
+ end.to raise_error(TypeError)
5490
5734
  end
5491
5735
  end
5492
5736
 
@@ -5530,9 +5774,9 @@ end
5530
5774
 
5531
5775
  describe Addressable::URI, "when form encoding a non-Array object" do
5532
5776
  it "should raise a TypeError for objects than cannot be converted" do
5533
- expect(lambda do
5777
+ expect do
5534
5778
  Addressable::URI.form_encode(42)
5535
- end).to raise_error(TypeError, "Can't convert Fixnum into Array.")
5779
+ end.to raise_error(TypeError)
5536
5780
  end
5537
5781
  end
5538
5782
 
@@ -5598,9 +5842,9 @@ describe Addressable::URI, "when form unencoding a non-String object" do
5598
5842
  end
5599
5843
 
5600
5844
  it "should raise a TypeError for objects than cannot be converted" do
5601
- expect(lambda do
5845
+ expect do
5602
5846
  Addressable::URI.form_unencode(42)
5603
- end).to raise_error(TypeError, "Can't convert Fixnum into String.")
5847
+ end.to raise_error(TypeError)
5604
5848
  end
5605
5849
  end
5606
5850
 
@@ -5610,15 +5854,15 @@ describe Addressable::URI, "when normalizing a non-String object" do
5610
5854
  end
5611
5855
 
5612
5856
  it "should raise a TypeError for objects than cannot be converted" do
5613
- expect(lambda do
5857
+ expect do
5614
5858
  Addressable::URI.normalize_component(42)
5615
- end).to raise_error(TypeError, "Can't convert Fixnum into String.")
5859
+ end.to raise_error(TypeError)
5616
5860
  end
5617
5861
 
5618
5862
  it "should raise a TypeError for objects than cannot be converted" do
5619
- expect(lambda do
5863
+ expect do
5620
5864
  Addressable::URI.normalize_component("component", 42)
5621
- end).to raise_error(TypeError)
5865
+ end.to raise_error(TypeError)
5622
5866
  end
5623
5867
  end
5624
5868
 
@@ -5690,6 +5934,18 @@ describe Addressable::URI, "when normalizing a string but leaving some character
5690
5934
  end
5691
5935
  end
5692
5936
 
5937
+ describe Addressable::URI, "when encoding IP literals" do
5938
+ it "should work for IPv4" do
5939
+ input = "http://127.0.0.1/"
5940
+ expect(Addressable::URI.encode(input)).to eq(input)
5941
+ end
5942
+
5943
+ it "should work for IPv6" do
5944
+ input = "http://[fe80::200:f8ff:fe21:67cf]/"
5945
+ expect(Addressable::URI.encode(input)).to eq(input)
5946
+ end
5947
+ end
5948
+
5693
5949
  describe Addressable::URI, "when encoding a string with existing encodings to upcase" do
5694
5950
  it "should result in correct percent encoded sequence" do
5695
5951
  expect(Addressable::URI.encode_component("JK%4c", "0-9A-IKM-Za-z%", "L")).to eq("%4AK%4C")
@@ -5762,41 +6018,41 @@ end
5762
6018
 
5763
6019
  describe Addressable::URI, "when unencoding a bogus object" do
5764
6020
  it "should raise a TypeError" do
5765
- expect(lambda do
6021
+ expect do
5766
6022
  Addressable::URI.unencode_component(42)
5767
- end).to raise_error(TypeError)
6023
+ end.to raise_error(TypeError)
5768
6024
  end
5769
6025
 
5770
6026
  it "should raise a TypeError" do
5771
- expect(lambda do
6027
+ expect do
5772
6028
  Addressable::URI.unencode("/path?g%C3%BCnther", Integer)
5773
- end).to raise_error(TypeError)
6029
+ end.to raise_error(TypeError)
5774
6030
  end
5775
6031
  end
5776
6032
 
5777
6033
  describe Addressable::URI, "when encoding a bogus object" do
5778
6034
  it "should raise a TypeError" do
5779
- expect(lambda do
6035
+ expect do
5780
6036
  Addressable::URI.encode(Object.new)
5781
- end).to raise_error(TypeError)
6037
+ end.to raise_error(TypeError)
5782
6038
  end
5783
6039
 
5784
6040
  it "should raise a TypeError" do
5785
- expect(lambda do
6041
+ expect do
5786
6042
  Addressable::URI.normalized_encode(Object.new)
5787
- end).to raise_error(TypeError)
6043
+ end.to raise_error(TypeError)
5788
6044
  end
5789
6045
 
5790
6046
  it "should raise a TypeError" do
5791
- expect(lambda do
6047
+ expect do
5792
6048
  Addressable::URI.encode_component("günther", Object.new)
5793
- end).to raise_error(TypeError)
6049
+ end.to raise_error(TypeError)
5794
6050
  end
5795
6051
 
5796
6052
  it "should raise a TypeError" do
5797
- expect(lambda do
6053
+ expect do
5798
6054
  Addressable::URI.encode_component(Object.new)
5799
- end).to raise_error(TypeError)
6055
+ end.to raise_error(TypeError)
5800
6056
  end
5801
6057
  end
5802
6058
 
@@ -5812,9 +6068,9 @@ describe Addressable::URI, "when given the input " +
5812
6068
  end
5813
6069
 
5814
6070
  it "should not raise error when frozen" do
5815
- expect(lambda do
6071
+ expect do
5816
6072
  Addressable::URI.heuristic_parse(@input).freeze.to_s
5817
- end).not_to raise_error
6073
+ end.not_to raise_error
5818
6074
  end
5819
6075
  end
5820
6076
 
@@ -5878,6 +6134,136 @@ describe Addressable::URI, "when given the input " +
5878
6134
  end
5879
6135
  end
5880
6136
 
6137
+ describe Addressable::URI, "when given the input " +
6138
+ "'http://prefix\\.example.com/'" do
6139
+ before do
6140
+ @input = "http://prefix\\.example.com/"
6141
+ end
6142
+
6143
+ it "should heuristically parse to 'http://prefix/.example.com/'" do
6144
+ @uri = Addressable::URI.heuristic_parse(@input)
6145
+ expect(@uri.authority).to eq("prefix")
6146
+ expect(@uri.to_s).to eq("http://prefix/.example.com/")
6147
+ end
6148
+
6149
+ it "should heuristically parse to 'http://prefix/.example.com/' " +
6150
+ "even with a scheme hint of 'ftp'" do
6151
+ @uri = Addressable::URI.heuristic_parse(@input, {:scheme => 'ftp'})
6152
+ expect(@uri.to_s).to eq("http://prefix/.example.com/")
6153
+ end
6154
+ end
6155
+
6156
+ describe Addressable::URI, "when given the input " +
6157
+ "'http://p:\\/'" do
6158
+ before do
6159
+ @input = "http://p:\\/"
6160
+ end
6161
+
6162
+ it "should heuristically parse to 'http://p//'" do
6163
+ @uri = Addressable::URI.heuristic_parse(@input)
6164
+ expect(@uri.authority).to eq("p")
6165
+ expect(@uri.to_s).to eq("http://p//")
6166
+ end
6167
+
6168
+ it "should heuristically parse to 'http://p//' " +
6169
+ "even with a scheme hint of 'ftp'" do
6170
+ @uri = Addressable::URI.heuristic_parse(@input, {:scheme => 'ftp'})
6171
+ expect(@uri.to_s).to eq("http://p//")
6172
+ end
6173
+ end
6174
+
6175
+ describe Addressable::URI, "when given the input " +
6176
+ "'http://p://'" do
6177
+ before do
6178
+ @input = "http://p://"
6179
+ end
6180
+
6181
+ it "should heuristically parse to 'http://p//'" do
6182
+ @uri = Addressable::URI.heuristic_parse(@input)
6183
+ expect(@uri.authority).to eq("p")
6184
+ expect(@uri.to_s).to eq("http://p//")
6185
+ end
6186
+
6187
+ it "should heuristically parse to 'http://p//' " +
6188
+ "even with a scheme hint of 'ftp'" do
6189
+ @uri = Addressable::URI.heuristic_parse(@input, {:scheme => 'ftp'})
6190
+ expect(@uri.to_s).to eq("http://p//")
6191
+ end
6192
+ end
6193
+
6194
+ describe Addressable::URI, "when given the input " +
6195
+ "'http://p://p'" do
6196
+ before do
6197
+ @input = "http://p://p"
6198
+ end
6199
+
6200
+ it "should heuristically parse to 'http://p//p'" do
6201
+ @uri = Addressable::URI.heuristic_parse(@input)
6202
+ expect(@uri.authority).to eq("p")
6203
+ expect(@uri.to_s).to eq("http://p//p")
6204
+ end
6205
+
6206
+ it "should heuristically parse to 'http://p//p' " +
6207
+ "even with a scheme hint of 'ftp'" do
6208
+ @uri = Addressable::URI.heuristic_parse(@input, {:scheme => 'ftp'})
6209
+ expect(@uri.to_s).to eq("http://p//p")
6210
+ end
6211
+ end
6212
+
6213
+ describe Addressable::URI, "when given the input " +
6214
+ "'http://prefix .example.com/'" do
6215
+ before do
6216
+ @input = "http://prefix .example.com/"
6217
+ end
6218
+
6219
+ # Justification here being that no browser actually tries to resolve this.
6220
+ # They all treat this as a web search.
6221
+ it "should heuristically parse to 'http://prefix%20.example.com/'" do
6222
+ @uri = Addressable::URI.heuristic_parse(@input)
6223
+ expect(@uri.authority).to eq("prefix%20.example.com")
6224
+ expect(@uri.to_s).to eq("http://prefix%20.example.com/")
6225
+ end
6226
+
6227
+ it "should heuristically parse to 'http://prefix%20.example.com/' " +
6228
+ "even with a scheme hint of 'ftp'" do
6229
+ @uri = Addressable::URI.heuristic_parse(@input, {:scheme => 'ftp'})
6230
+ expect(@uri.to_s).to eq("http://prefix%20.example.com/")
6231
+ end
6232
+ end
6233
+
6234
+ describe Addressable::URI, "when given the input " +
6235
+ "' http://www.example.com/ '" do
6236
+ before do
6237
+ @input = " http://www.example.com/ "
6238
+ end
6239
+
6240
+ it "should heuristically parse to 'http://prefix%20.example.com/'" do
6241
+ @uri = Addressable::URI.heuristic_parse(@input)
6242
+ expect(@uri.scheme).to eq("http")
6243
+ expect(@uri.path).to eq("/")
6244
+ expect(@uri.to_s).to eq("http://www.example.com/")
6245
+ end
6246
+ end
6247
+
6248
+ describe Addressable::URI, "when given the input " +
6249
+ "'http://prefix%2F.example.com/'" do
6250
+ before do
6251
+ @input = "http://prefix%2F.example.com/"
6252
+ end
6253
+
6254
+ it "should heuristically parse to 'http://prefix%2F.example.com/'" do
6255
+ @uri = Addressable::URI.heuristic_parse(@input)
6256
+ expect(@uri.authority).to eq("prefix%2F.example.com")
6257
+ expect(@uri.to_s).to eq("http://prefix%2F.example.com/")
6258
+ end
6259
+
6260
+ it "should heuristically parse to 'http://prefix%2F.example.com/' " +
6261
+ "even with a scheme hint of 'ftp'" do
6262
+ @uri = Addressable::URI.heuristic_parse(@input, {:scheme => 'ftp'})
6263
+ expect(@uri.to_s).to eq("http://prefix%2F.example.com/")
6264
+ end
6265
+ end
6266
+
5881
6267
  describe Addressable::URI, "when given the input " +
5882
6268
  "'/path/to/resource'" do
5883
6269
  before do
@@ -5964,6 +6350,18 @@ describe Addressable::URI, "when given the input " +
5964
6350
  end
5965
6351
  end
5966
6352
 
6353
+ describe Addressable::URI, "when given the input which "\
6354
+ "start with digits and has specified port" do
6355
+ before do
6356
+ @input = "7777.example.org:8089"
6357
+ end
6358
+
6359
+ it "should heuristically parse to 'http://7777.example.org:8089'" do
6360
+ uri = Addressable::URI.heuristic_parse(@input)
6361
+ expect(uri.to_s).to eq("http://7777.example.org:8089")
6362
+ end
6363
+ end
6364
+
5967
6365
  describe Addressable::URI, "when given the input " +
5968
6366
  "'feed:///example.com'" do
5969
6367
  before do
@@ -5976,6 +6374,18 @@ describe Addressable::URI, "when given the input " +
5976
6374
  end
5977
6375
  end
5978
6376
 
6377
+ describe Addressable::URI, "when given the input " +
6378
+ "'file://localhost/path/to/resource/'" do
6379
+ before do
6380
+ @input = "file://localhost/path/to/resource/"
6381
+ end
6382
+
6383
+ it "should heuristically parse to 'file:///path/to/resource/'" do
6384
+ @uri = Addressable::URI.heuristic_parse(@input)
6385
+ expect(@uri.to_s).to eq("file:///path/to/resource/")
6386
+ end
6387
+ end
6388
+
5979
6389
  describe Addressable::URI, "when given the input " +
5980
6390
  "'file://path/to/resource/'" do
5981
6391
  before do
@@ -5988,6 +6398,18 @@ describe Addressable::URI, "when given the input " +
5988
6398
  end
5989
6399
  end
5990
6400
 
6401
+ describe Addressable::URI, "when given the input " +
6402
+ "'file://///path/to/resource/'" do
6403
+ before do
6404
+ @input = "file:///////path/to/resource/"
6405
+ end
6406
+
6407
+ it "should heuristically parse to 'file:////path/to/resource/'" do
6408
+ @uri = Addressable::URI.heuristic_parse(@input)
6409
+ expect(@uri.to_s).to eq("file:////path/to/resource/")
6410
+ end
6411
+ end
6412
+
5991
6413
  describe Addressable::URI, "when given the input " +
5992
6414
  "'feed://http://example.com'" do
5993
6415
  before do
@@ -6012,6 +6434,44 @@ describe Addressable::URI, "when given the input " +
6012
6434
  end
6013
6435
  end
6014
6436
 
6437
+ describe Addressable::URI, "when given the input: 'user@domain.com'" do
6438
+ before do
6439
+ @input = "user@domain.com"
6440
+ end
6441
+
6442
+ context "for heuristic parse" do
6443
+ it "should remain 'mailto:user@domain.com'" do
6444
+ uri = Addressable::URI.heuristic_parse("mailto:#{@input}")
6445
+ expect(uri.to_s).to eq("mailto:user@domain.com")
6446
+ end
6447
+
6448
+ it "should have a scheme of 'mailto'" do
6449
+ uri = Addressable::URI.heuristic_parse(@input)
6450
+ expect(uri.to_s).to eq("mailto:user@domain.com")
6451
+ expect(uri.scheme).to eq("mailto")
6452
+ end
6453
+
6454
+ it "should remain 'acct:user@domain.com'" do
6455
+ uri = Addressable::URI.heuristic_parse("acct:#{@input}")
6456
+ expect(uri.to_s).to eq("acct:user@domain.com")
6457
+ end
6458
+
6459
+ context "HTTP" do
6460
+ before do
6461
+ @uri = Addressable::URI.heuristic_parse("http://#{@input}/")
6462
+ end
6463
+
6464
+ it "should remain 'http://user@domain.com/'" do
6465
+ expect(@uri.to_s).to eq("http://user@domain.com/")
6466
+ end
6467
+
6468
+ it "should have the username 'user' for HTTP basic authentication" do
6469
+ expect(@uri.user).to eq("user")
6470
+ end
6471
+ end
6472
+ end
6473
+ end
6474
+
6015
6475
  describe Addressable::URI, "when assigning query values" do
6016
6476
  before do
6017
6477
  @uri = Addressable::URI.new
@@ -6023,54 +6483,54 @@ describe Addressable::URI, "when assigning query values" do
6023
6483
  end
6024
6484
 
6025
6485
  it "should raise an error attempting to assign {'a' => {'b' => ['c']}}" do
6026
- expect(lambda do
6486
+ expect do
6027
6487
  @uri.query_values = { 'a' => {'b' => ['c'] } }
6028
- end).to raise_error(TypeError)
6488
+ end.to raise_error(TypeError)
6029
6489
  end
6030
6490
 
6031
6491
  it "should raise an error attempting to assign " +
6032
6492
  "{:b => '2', :a => {:c => '1'}}" do
6033
- expect(lambda do
6493
+ expect do
6034
6494
  @uri.query_values = {:b => '2', :a => {:c => '1'}}
6035
- end).to raise_error(TypeError)
6495
+ end.to raise_error(TypeError)
6036
6496
  end
6037
6497
 
6038
6498
  it "should raise an error attempting to assign " +
6039
6499
  "{:a => 'a', :b => [{:c => 'c', :d => 'd'}, " +
6040
6500
  "{:e => 'e', :f => 'f'}]}" do
6041
- expect(lambda do
6501
+ expect do
6042
6502
  @uri.query_values = {
6043
6503
  :a => "a", :b => [{:c => "c", :d => "d"}, {:e => "e", :f => "f"}]
6044
6504
  }
6045
- end).to raise_error(TypeError)
6505
+ end.to raise_error(TypeError)
6046
6506
  end
6047
6507
 
6048
6508
  it "should raise an error attempting to assign " +
6049
6509
  "{:a => 'a', :b => [{:c => true, :d => 'd'}, " +
6050
6510
  "{:e => 'e', :f => 'f'}]}" do
6051
- expect(lambda do
6511
+ expect do
6052
6512
  @uri.query_values = {
6053
6513
  :a => 'a', :b => [{:c => true, :d => 'd'}, {:e => 'e', :f => 'f'}]
6054
6514
  }
6055
- end).to raise_error(TypeError)
6515
+ end.to raise_error(TypeError)
6056
6516
  end
6057
6517
 
6058
6518
  it "should raise an error attempting to assign " +
6059
6519
  "{:a => 'a', :b => {:c => true, :d => 'd'}}" do
6060
- expect(lambda do
6520
+ expect do
6061
6521
  @uri.query_values = {
6062
6522
  :a => 'a', :b => {:c => true, :d => 'd'}
6063
6523
  }
6064
- end).to raise_error(TypeError)
6524
+ end.to raise_error(TypeError)
6065
6525
  end
6066
6526
 
6067
6527
  it "should raise an error attempting to assign " +
6068
6528
  "{:a => 'a', :b => {:c => true, :d => 'd'}}" do
6069
- expect(lambda do
6529
+ expect do
6070
6530
  @uri.query_values = {
6071
6531
  :a => 'a', :b => {:c => true, :d => 'd'}
6072
6532
  }
6073
- end).to raise_error(TypeError)
6533
+ end.to raise_error(TypeError)
6074
6534
  end
6075
6535
 
6076
6536
  it "should correctly assign {:a => 1, :b => 1.5}" do
@@ -6081,13 +6541,13 @@ describe Addressable::URI, "when assigning query values" do
6081
6541
  it "should raise an error attempting to assign " +
6082
6542
  "{:z => 1, :f => [2, {999.1 => [3,'4']}, ['h', 'i']], " +
6083
6543
  ":a => {:b => ['c', 'd'], :e => true, :y => 0.5}}" do
6084
- expect(lambda do
6544
+ expect do
6085
6545
  @uri.query_values = {
6086
6546
  :z => 1,
6087
6547
  :f => [ 2, {999.1 => [3,'4']}, ['h', 'i'] ],
6088
6548
  :a => { :b => ['c', 'd'], :e => true, :y => 0.5 }
6089
6549
  }
6090
- end).to raise_error(TypeError)
6550
+ end.to raise_error(TypeError)
6091
6551
  end
6092
6552
 
6093
6553
  it "should correctly assign {}" do
@@ -6137,7 +6597,7 @@ describe Addressable::URI, "when assigning path values" do
6137
6597
  @uri.path = "acct:bob@sporkmonger.com"
6138
6598
  expect(@uri.path).to eq("acct:bob@sporkmonger.com")
6139
6599
  expect(@uri.normalize.to_str).to eq("acct%2Fbob@sporkmonger.com")
6140
- expect(lambda { @uri.to_s }).to raise_error(
6600
+ expect { @uri.to_s }.to raise_error(
6141
6601
  Addressable::URI::InvalidURIError
6142
6602
  )
6143
6603
  end
@@ -6155,26 +6615,26 @@ describe Addressable::URI, "when assigning path values" do
6155
6615
  end
6156
6616
 
6157
6617
  it "should not allow relative paths to be assigned on absolute URIs" do
6158
- expect(lambda do
6618
+ expect do
6159
6619
  @uri.scheme = "http"
6160
6620
  @uri.host = "example.com"
6161
6621
  @uri.path = "acct:bob@sporkmonger.com"
6162
- end).to raise_error(Addressable::URI::InvalidURIError)
6622
+ end.to raise_error(Addressable::URI::InvalidURIError)
6163
6623
  end
6164
6624
 
6165
6625
  it "should not allow relative paths to be assigned on absolute URIs" do
6166
- expect(lambda do
6626
+ expect do
6167
6627
  @uri.path = "acct:bob@sporkmonger.com"
6168
6628
  @uri.scheme = "http"
6169
6629
  @uri.host = "example.com"
6170
- end).to raise_error(Addressable::URI::InvalidURIError)
6630
+ end.to raise_error(Addressable::URI::InvalidURIError)
6171
6631
  end
6172
6632
 
6173
6633
  it "should not allow relative paths to be assigned on absolute URIs" do
6174
- expect(lambda do
6634
+ expect do
6175
6635
  @uri.path = "uuid:0b3ecf60-3f93-11df-a9c3-001f5bfffe12"
6176
6636
  @uri.scheme = "urn"
6177
- end).not_to raise_error
6637
+ end.not_to raise_error
6178
6638
  end
6179
6639
  end
6180
6640