addressable 2.5.2 → 2.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # encoding:utf-8
2
4
  #--
3
5
  # Copyright (C) Bob Aman
@@ -21,8 +23,8 @@ if !defined?(Addressable::VERSION)
21
23
  module Addressable
22
24
  module VERSION
23
25
  MAJOR = 2
24
- MINOR = 5
25
- TINY = 2
26
+ MINOR = 8
27
+ TINY = 0
26
28
 
27
29
  STRING = [MAJOR, MINOR, TINY].join('.')
28
30
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # coding: utf-8
2
4
  # Copyright (C) Bob Aman
3
5
  #
@@ -26,9 +28,9 @@ shared_examples_for "converting from unicode to ASCII" do
26
28
  expect(Addressable::IDNA.to_ascii("www.google.com")).to eq("www.google.com")
27
29
  end
28
30
 
29
- LONG = 'AcinusFallumTrompetumNullunCreditumVisumEstAtCuadLongumEtCefallum.com'
30
- it "should convert '#{LONG}' correctly" do
31
- expect(Addressable::IDNA.to_ascii(LONG)).to eq(LONG)
31
+ long = 'AcinusFallumTrompetumNullunCreditumVisumEstAtCuadLongumEtCefallum.com'
32
+ it "should convert '#{long}' correctly" do
33
+ expect(Addressable::IDNA.to_ascii(long)).to eq(long)
32
34
  end
33
35
 
34
36
  it "should convert 'www.詹姆斯.com' correctly" do
@@ -148,9 +150,9 @@ shared_examples_for "converting from unicode to ASCII" do
148
150
  end
149
151
 
150
152
  shared_examples_for "converting from ASCII to unicode" do
151
- LONG = 'AcinusFallumTrompetumNullunCreditumVisumEstAtCuadLongumEtCefallum.com'
152
- it "should convert '#{LONG}' correctly" do
153
- expect(Addressable::IDNA.to_unicode(LONG)).to eq(LONG)
153
+ long = 'AcinusFallumTrompetumNullunCreditumVisumEstAtCuadLongumEtCefallum.com'
154
+ it "should convert '#{long}' correctly" do
155
+ expect(Addressable::IDNA.to_unicode(long)).to eq(long)
154
156
  end
155
157
 
156
158
  it "should return the identity conversion when punycode decode fails" do
@@ -292,7 +294,9 @@ begin
292
294
  it_should_behave_like "converting from unicode to ASCII"
293
295
  it_should_behave_like "converting from ASCII to unicode"
294
296
  end
295
- rescue LoadError
297
+ rescue LoadError => error
298
+ raise error if ENV["CI"] && TestHelper.native_supported?
299
+
296
300
  # Cannot test the native implementation without libidn support.
297
301
  warn('Could not load native IDN implementation.')
298
302
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # coding: utf-8
2
4
  # Copyright (C) Bob Aman
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # coding: utf-8
2
4
  # Copyright (C) Bob Aman
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # coding: utf-8
2
4
  # Copyright (C) Bob Aman
3
5
  #
@@ -17,6 +19,7 @@
17
19
  require "spec_helper"
18
20
 
19
21
  require "bigdecimal"
22
+ require "timeout"
20
23
  require "addressable/template"
21
24
 
22
25
  shared_examples_for 'expands' do |tests|
@@ -82,7 +85,7 @@ describe "Type conversion" do
82
85
  :hello => 1234,
83
86
  :nothing => nil,
84
87
  :sym => :symbolic,
85
- :decimal => BigDecimal.new('1')
88
+ :decimal => BigDecimal('1')
86
89
  }
87
90
  }
88
91
 
@@ -949,6 +952,36 @@ describe Addressable::Template do
949
952
  )
950
953
  end
951
954
  end
955
+ context "issue #307 - partial_expand form query with nil params" do
956
+ subject do
957
+ Addressable::Template.new("http://example.com/{?one,two,three}/")
958
+ end
959
+ it "builds a new pattern with two=nil" do
960
+ expect(subject.partial_expand(two: nil).pattern).to eq(
961
+ "http://example.com/{?one}{&three}/"
962
+ )
963
+ end
964
+ it "builds a new pattern with one=nil and two=nil" do
965
+ expect(subject.partial_expand(one: nil, two: nil).pattern).to eq(
966
+ "http://example.com/{?three}/"
967
+ )
968
+ end
969
+ it "builds a new pattern with one=1 and two=nil" do
970
+ expect(subject.partial_expand(one: 1, two: nil).pattern).to eq(
971
+ "http://example.com/?one=1{&three}/"
972
+ )
973
+ end
974
+ it "builds a new pattern with one=nil and two=2" do
975
+ expect(subject.partial_expand(one: nil, two: 2).pattern).to eq(
976
+ "http://example.com/?two=2{&three}/"
977
+ )
978
+ end
979
+ it "builds a new pattern with one=nil" do
980
+ expect(subject.partial_expand(one: nil).pattern).to eq(
981
+ "http://example.com/{?two}{&three}/"
982
+ )
983
+ end
984
+ end
952
985
  context "partial_expand with query string" do
953
986
  subject {
954
987
  Addressable::Template.new("http://example.com/{?two,one}/")
@@ -1308,6 +1341,14 @@ describe Addressable::Template do
1308
1341
  expect(subject).not_to match("foo_bar*")
1309
1342
  expect(subject).not_to match("foo_bar:20")
1310
1343
  end
1344
+
1345
+ it 'should parse in a reasonable time' do
1346
+ expect do
1347
+ Timeout.timeout(0.1) do
1348
+ expect(subject).not_to match("0"*25 + "!")
1349
+ end
1350
+ end.not_to raise_error
1351
+ end
1311
1352
  end
1312
1353
  context "VARIABLE_LIST" do
1313
1354
  subject { Addressable::Template::VARIABLE_LIST }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # coding: utf-8
2
4
  # Copyright (C) Bob Aman
3
5
  #
@@ -63,116 +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)
126
+ end.to raise_error(TypeError)
125
127
  end
126
128
  end
127
129
 
128
130
  describe Addressable::URI, "when created with a non-string path" do
129
131
  it "should raise an error" do
130
- expect(lambda do
132
+ expect do
131
133
  Addressable::URI.new(:path => :bogus)
132
- end).to raise_error(TypeError)
134
+ end.to raise_error(TypeError)
133
135
  end
134
136
  end
135
137
 
136
138
  describe Addressable::URI, "when created with a non-string query" do
137
139
  it "should raise an error" do
138
- expect(lambda do
140
+ expect do
139
141
  Addressable::URI.new(:query => :bogus)
140
- end).to raise_error(TypeError)
142
+ end.to raise_error(TypeError)
141
143
  end
142
144
  end
143
145
 
144
146
  describe Addressable::URI, "when created with a non-string fragment" do
145
147
  it "should raise an error" do
146
- expect(lambda do
148
+ expect do
147
149
  Addressable::URI.new(:fragment => :bogus)
148
- end).to raise_error(TypeError)
150
+ end.to raise_error(TypeError)
149
151
  end
150
152
  end
151
153
 
152
154
  describe Addressable::URI, "when created with a scheme but no hierarchical " +
153
155
  "segment" do
154
156
  it "should raise an error" do
155
- expect(lambda do
157
+ expect do
156
158
  Addressable::URI.parse("http:")
157
- end).to raise_error(Addressable::URI::InvalidURIError)
159
+ end.to raise_error(Addressable::URI::InvalidURIError)
158
160
  end
159
161
  end
160
162
 
161
163
  describe Addressable::URI, "quote handling" do
162
164
  describe 'in host name' do
163
165
  it "should raise an error for single quote" do
164
- expect(lambda do
166
+ expect do
165
167
  Addressable::URI.parse("http://local\"host/")
166
- end).to raise_error(Addressable::URI::InvalidURIError)
168
+ end.to raise_error(Addressable::URI::InvalidURIError)
167
169
  end
168
170
  end
169
171
  end
170
172
 
171
173
  describe Addressable::URI, "newline normalization" do
172
174
  it "should not accept newlines in scheme" do
173
- expect(lambda do
175
+ expect do
174
176
  Addressable::URI.parse("ht%0atp://localhost/")
175
- end).to raise_error(Addressable::URI::InvalidURIError)
177
+ end.to raise_error(Addressable::URI::InvalidURIError)
176
178
  end
177
179
 
178
180
  it "should not unescape newline in path" do
@@ -197,47 +199,47 @@ describe Addressable::URI, "newline normalization" do
197
199
 
198
200
  it "should not accept newline in hostname" do
199
201
  uri = Addressable::URI.parse("http://localhost/")
200
- expect(lambda do
202
+ expect do
201
203
  uri.host = "local\nhost"
202
- end).to raise_error(Addressable::URI::InvalidURIError)
204
+ end.to raise_error(Addressable::URI::InvalidURIError)
203
205
  end
204
206
  end
205
207
 
206
208
  describe Addressable::URI, "when created with ambiguous path" do
207
209
  it "should raise an error" do
208
- expect(lambda do
210
+ expect do
209
211
  Addressable::URI.parse("::http")
210
- end).to raise_error(Addressable::URI::InvalidURIError)
212
+ end.to raise_error(Addressable::URI::InvalidURIError)
211
213
  end
212
214
  end
213
215
 
214
216
  describe Addressable::URI, "when created with an invalid host" do
215
217
  it "should raise an error" do
216
- expect(lambda do
218
+ expect do
217
219
  Addressable::URI.new(:host => "<invalid>")
218
- end).to raise_error(Addressable::URI::InvalidURIError)
220
+ end.to raise_error(Addressable::URI::InvalidURIError)
219
221
  end
220
222
  end
221
223
 
222
224
  describe Addressable::URI, "when created with a host consisting of " +
223
225
  "sub-delims characters" do
224
226
  it "should not raise an error" do
225
- expect(lambda do
227
+ expect do
226
228
  Addressable::URI.new(
227
229
  :host => Addressable::URI::CharacterClasses::SUB_DELIMS.gsub(/\\/, '')
228
230
  )
229
- end).not_to raise_error
231
+ end.not_to raise_error
230
232
  end
231
233
  end
232
234
 
233
235
  describe Addressable::URI, "when created with a host consisting of " +
234
236
  "unreserved characters" do
235
237
  it "should not raise an error" do
236
- expect(lambda do
238
+ expect do
237
239
  Addressable::URI.new(
238
240
  :host => Addressable::URI::CharacterClasses::UNRESERVED.gsub(/\\/, '')
239
241
  )
240
- end).not_to raise_error
242
+ end.not_to raise_error
241
243
  end
242
244
  end
243
245
 
@@ -267,83 +269,83 @@ describe Addressable::URI, "when created from nil components" do
267
269
  end
268
270
 
269
271
  it "should raise an error if the scheme is set to whitespace" do
270
- expect(lambda do
272
+ expect do
271
273
  @uri.scheme = "\t \n"
272
- end).to raise_error(Addressable::URI::InvalidURIError)
274
+ end.to raise_error(Addressable::URI::InvalidURIError, /'\t \n'/)
273
275
  end
274
276
 
275
277
  it "should raise an error if the scheme is set to all digits" do
276
- expect(lambda do
278
+ expect do
277
279
  @uri.scheme = "123"
278
- end).to raise_error(Addressable::URI::InvalidURIError)
280
+ end.to raise_error(Addressable::URI::InvalidURIError, /'123'/)
279
281
  end
280
282
 
281
283
  it "should raise an error if the scheme begins with a digit" do
282
- expect(lambda do
284
+ expect do
283
285
  @uri.scheme = "1scheme"
284
- end).to raise_error(Addressable::URI::InvalidURIError)
286
+ end.to raise_error(Addressable::URI::InvalidURIError, /'1scheme'/)
285
287
  end
286
288
 
287
289
  it "should raise an error if the scheme begins with a plus" do
288
- expect(lambda do
290
+ expect do
289
291
  @uri.scheme = "+scheme"
290
- end).to raise_error(Addressable::URI::InvalidURIError)
292
+ end.to raise_error(Addressable::URI::InvalidURIError, /'\+scheme'/)
291
293
  end
292
294
 
293
295
  it "should raise an error if the scheme begins with a dot" do
294
- expect(lambda do
296
+ expect do
295
297
  @uri.scheme = ".scheme"
296
- end).to raise_error(Addressable::URI::InvalidURIError)
298
+ end.to raise_error(Addressable::URI::InvalidURIError, /'\.scheme'/)
297
299
  end
298
300
 
299
301
  it "should raise an error if the scheme begins with a dash" do
300
- expect(lambda do
302
+ expect do
301
303
  @uri.scheme = "-scheme"
302
- end).to raise_error(Addressable::URI::InvalidURIError)
304
+ end.to raise_error(Addressable::URI::InvalidURIError, /'-scheme'/)
303
305
  end
304
306
 
305
307
  it "should raise an error if the scheme contains an illegal character" do
306
- expect(lambda do
308
+ expect do
307
309
  @uri.scheme = "scheme!"
308
- end).to raise_error(Addressable::URI::InvalidURIError)
310
+ end.to raise_error(Addressable::URI::InvalidURIError, /'scheme!'/)
309
311
  end
310
312
 
311
313
  it "should raise an error if the scheme contains whitespace" do
312
- expect(lambda do
314
+ expect do
313
315
  @uri.scheme = "sch eme"
314
- end).to raise_error(Addressable::URI::InvalidURIError)
316
+ end.to raise_error(Addressable::URI::InvalidURIError, /'sch eme'/)
315
317
  end
316
318
 
317
319
  it "should raise an error if the scheme contains a newline" do
318
- expect(lambda do
320
+ expect do
319
321
  @uri.scheme = "sch\neme"
320
- end).to raise_error(Addressable::URI::InvalidURIError)
322
+ end.to raise_error(Addressable::URI::InvalidURIError)
321
323
  end
322
324
 
323
325
  it "should raise an error if set into an invalid state" do
324
- expect(lambda do
326
+ expect do
325
327
  @uri.user = "user"
326
- end).to raise_error(Addressable::URI::InvalidURIError)
328
+ end.to raise_error(Addressable::URI::InvalidURIError)
327
329
  end
328
330
 
329
331
  it "should raise an error if set into an invalid state" do
330
- expect(lambda do
332
+ expect do
331
333
  @uri.password = "pass"
332
- end).to raise_error(Addressable::URI::InvalidURIError)
334
+ end.to raise_error(Addressable::URI::InvalidURIError)
333
335
  end
334
336
 
335
337
  it "should raise an error if set into an invalid state" do
336
- expect(lambda do
338
+ expect do
337
339
  @uri.scheme = "http"
338
340
  @uri.fragment = "fragment"
339
- end).to raise_error(Addressable::URI::InvalidURIError)
341
+ end.to raise_error(Addressable::URI::InvalidURIError)
340
342
  end
341
343
 
342
344
  it "should raise an error if set into an invalid state" do
343
- expect(lambda do
345
+ expect do
344
346
  @uri.fragment = "fragment"
345
347
  @uri.scheme = "http"
346
- end).to raise_error(Addressable::URI::InvalidURIError)
348
+ end.to raise_error(Addressable::URI::InvalidURIError)
347
349
  end
348
350
  end
349
351
 
@@ -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
 
@@ -1075,33 +1077,33 @@ end
1075
1077
 
1076
1078
  describe Addressable::URI, "when created with a host with a backslash" do
1077
1079
  it "should raise an error" do
1078
- expect(lambda do
1080
+ expect do
1079
1081
  Addressable::URI.new(:authority => "example\\example")
1080
- end).to raise_error(Addressable::URI::InvalidURIError)
1082
+ end.to raise_error(Addressable::URI::InvalidURIError)
1081
1083
  end
1082
1084
  end
1083
1085
 
1084
1086
  describe Addressable::URI, "when created with a host with a slash" do
1085
1087
  it "should raise an error" do
1086
- expect(lambda do
1088
+ expect do
1087
1089
  Addressable::URI.new(:authority => "example/example")
1088
- end).to raise_error(Addressable::URI::InvalidURIError)
1090
+ end.to raise_error(Addressable::URI::InvalidURIError)
1089
1091
  end
1090
1092
  end
1091
1093
 
1092
1094
  describe Addressable::URI, "when created with a host with a space" do
1093
1095
  it "should raise an error" do
1094
- expect(lambda do
1096
+ expect do
1095
1097
  Addressable::URI.new(:authority => "example example")
1096
- end).to raise_error(Addressable::URI::InvalidURIError)
1098
+ end.to raise_error(Addressable::URI::InvalidURIError)
1097
1099
  end
1098
1100
  end
1099
1101
 
1100
1102
  describe Addressable::URI, "when created with both a userinfo and a user" do
1101
1103
  it "should raise an error" do
1102
- expect(lambda do
1104
+ expect do
1103
1105
  Addressable::URI.new(:user => "user", :userinfo => "user:pass")
1104
- end).to raise_error(ArgumentError)
1106
+ end.to raise_error(ArgumentError)
1105
1107
  end
1106
1108
  end
1107
1109
 
@@ -1193,18 +1195,18 @@ describe Addressable::URI, "when parsed from something that looks " +
1193
1195
  "like a URI object" do
1194
1196
  it "should parse without error" do
1195
1197
  uri = Addressable::URI.parse(Fake::URI::HTTP.new("http://example.com/"))
1196
- expect(lambda do
1198
+ expect do
1197
1199
  Addressable::URI.parse(uri)
1198
- end).not_to raise_error
1200
+ end.not_to raise_error
1199
1201
  end
1200
1202
  end
1201
1203
 
1202
1204
  describe Addressable::URI, "when parsed from a standard library URI object" do
1203
1205
  it "should parse without error" do
1204
1206
  uri = Addressable::URI.parse(URI.parse("http://example.com/"))
1205
- expect(lambda do
1207
+ expect do
1206
1208
  Addressable::URI.parse(uri)
1207
- end).not_to raise_error
1209
+ end.not_to raise_error
1208
1210
  end
1209
1211
  end
1210
1212
 
@@ -1364,9 +1366,9 @@ describe Addressable::URI, "when parsed from " +
1364
1366
  end
1365
1367
 
1366
1368
  it "should not allow request URI assignment" do
1367
- expect(lambda do
1369
+ expect do
1368
1370
  @uri.request_uri = "/"
1369
- end).to raise_error(Addressable::URI::InvalidURIError)
1371
+ end.to raise_error(Addressable::URI::InvalidURIError)
1370
1372
  end
1371
1373
 
1372
1374
  it "should have a query of 'objectClass?one'" do
@@ -1388,9 +1390,9 @@ describe Addressable::URI, "when parsed from " +
1388
1390
  end
1389
1391
 
1390
1392
  it "should raise an error if omission would create an invalid URI" do
1391
- expect(lambda do
1393
+ expect do
1392
1394
  @uri.omit(:authority, :path)
1393
- end).to raise_error(Addressable::URI::InvalidURIError)
1395
+ end.to raise_error(Addressable::URI::InvalidURIError)
1394
1396
  end
1395
1397
 
1396
1398
  it "should have an origin of 'ldap://[2001:db8::7]'" do
@@ -1776,9 +1778,9 @@ describe Addressable::URI, "when parsed from " +
1776
1778
 
1777
1779
  it "should not be roughly equal to the string " +
1778
1780
  "'http://example.com:bogus/'" do
1779
- expect(lambda do
1781
+ expect do
1780
1782
  expect(@uri === "http://example.com:bogus/").to eq(false)
1781
- end).not_to raise_error
1783
+ end.not_to raise_error
1782
1784
  end
1783
1785
 
1784
1786
  it "should result in itself when joined with itself" do
@@ -1808,21 +1810,21 @@ describe Addressable::URI, "when parsed from " +
1808
1810
  end
1809
1811
 
1810
1812
  it "should not allow origin assignment without scheme" do
1811
- expect(lambda do
1813
+ expect do
1812
1814
  @uri.origin = "example.com"
1813
- end).to raise_error(Addressable::URI::InvalidURIError)
1815
+ end.to raise_error(Addressable::URI::InvalidURIError)
1814
1816
  end
1815
1817
 
1816
1818
  it "should not allow origin assignment without host" do
1817
- expect(lambda do
1819
+ expect do
1818
1820
  @uri.origin = "http://"
1819
- end).to raise_error(Addressable::URI::InvalidURIError)
1821
+ end.to raise_error(Addressable::URI::InvalidURIError)
1820
1822
  end
1821
1823
 
1822
1824
  it "should not allow origin assignment with bogus type" do
1823
- expect(lambda do
1825
+ expect do
1824
1826
  @uri.origin = :bogus
1825
- end).to raise_error(TypeError)
1827
+ end.to raise_error(TypeError)
1826
1828
  end
1827
1829
 
1828
1830
  # Section 6.2.3 of RFC 3986
@@ -1878,9 +1880,9 @@ describe Addressable::URI, "when parsed from " +
1878
1880
  end
1879
1881
 
1880
1882
  it "when joined with a bogus object a TypeError should be raised" do
1881
- expect(lambda do
1883
+ expect do
1882
1884
  @uri.join(42)
1883
- end).to raise_error(TypeError)
1885
+ end.to raise_error(TypeError)
1884
1886
  end
1885
1887
 
1886
1888
  it "should have the correct username after assignment" do
@@ -1984,6 +1986,20 @@ describe Addressable::URI, "when parsed from " +
1984
1986
  expect(@uri.request_uri).to eq("/pub/WWW/TheProject.html")
1985
1987
  end
1986
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
+
1987
2003
  it "should have the correct request URI after assignment" do
1988
2004
  @uri.request_uri = "/some/where/else.html?query?string"
1989
2005
  expect(@uri.request_uri).to eq("/some/where/else.html?query?string")
@@ -1999,15 +2015,15 @@ describe Addressable::URI, "when parsed from " +
1999
2015
  end
2000
2016
 
2001
2017
  it "should raise an error if the site value is set to something bogus" do
2002
- expect(lambda do
2018
+ expect do
2003
2019
  @uri.site = 42
2004
- end).to raise_error(TypeError)
2020
+ end.to raise_error(TypeError)
2005
2021
  end
2006
2022
 
2007
2023
  it "should raise an error if the request URI is set to something bogus" do
2008
- expect(lambda do
2024
+ expect do
2009
2025
  @uri.request_uri = 42
2010
- end).to raise_error(TypeError)
2026
+ end.to raise_error(TypeError)
2011
2027
  end
2012
2028
 
2013
2029
  it "should correctly convert to a hash" do
@@ -2056,9 +2072,9 @@ describe Addressable::URI, "when parsing IPv6 addresses" do
2056
2072
 
2057
2073
  it "should raise an error for " +
2058
2074
  "'http://[<invalid>]/'" do
2059
- expect(lambda do
2075
+ expect do
2060
2076
  Addressable::URI.parse("http://[<invalid>]/")
2061
- end).to raise_error(Addressable::URI::InvalidURIError)
2077
+ end.to raise_error(Addressable::URI::InvalidURIError)
2062
2078
  end
2063
2079
  end
2064
2080
 
@@ -2084,9 +2100,9 @@ describe Addressable::URI, "when assigning IPv6 address" do
2084
2100
  it "should not allow to set bare IPv6 address as host" do
2085
2101
  uri = Addressable::URI.parse("http://[::1]/")
2086
2102
  skip "not checked"
2087
- expect(lambda do
2103
+ expect do
2088
2104
  uri.host = '3ffe:1900:4545:3:200:f8ff:fe21:67cf'
2089
- end).to raise_error(Addressable::URI::InvalidURIError)
2105
+ end.to raise_error(Addressable::URI::InvalidURIError)
2090
2106
  end
2091
2107
  end
2092
2108
 
@@ -2118,9 +2134,9 @@ describe Addressable::URI, "when parsing IPvFuture addresses" do
2118
2134
 
2119
2135
  it "should raise an error for " +
2120
2136
  "'http://[v0.<invalid>]/'" do
2121
- expect(lambda do
2137
+ expect do
2122
2138
  Addressable::URI.parse("http://[v0.<invalid>]/")
2123
- end).to raise_error(Addressable::URI::InvalidURIError)
2139
+ end.to raise_error(Addressable::URI::InvalidURIError)
2124
2140
  end
2125
2141
  end
2126
2142
 
@@ -2464,9 +2480,9 @@ describe Addressable::URI, "when parsed from " +
2464
2480
  end
2465
2481
 
2466
2482
  it "should not raise an exception when normalized" do
2467
- expect(lambda do
2483
+ expect do
2468
2484
  @uri.normalize
2469
- end).not_to raise_error
2485
+ end.not_to raise_error
2470
2486
  end
2471
2487
 
2472
2488
  it "should be considered to be in normal form" do
@@ -2518,9 +2534,9 @@ describe Addressable::URI, "when parsed from " +
2518
2534
  end
2519
2535
 
2520
2536
  it "should not raise an exception when normalized" do
2521
- expect(lambda do
2537
+ expect do
2522
2538
  @uri.normalize
2523
- end).not_to raise_error
2539
+ end.not_to raise_error
2524
2540
  end
2525
2541
 
2526
2542
  it "should be considered to be in normal form" do
@@ -2543,9 +2559,9 @@ describe Addressable::URI, "when parsed from " +
2543
2559
  end
2544
2560
 
2545
2561
  it "should not raise an exception when normalized" do
2546
- expect(lambda do
2562
+ expect do
2547
2563
  @uri.normalize
2548
- end).not_to raise_error
2564
+ end.not_to raise_error
2549
2565
  end
2550
2566
 
2551
2567
  it "should be considered to be in normal form" do
@@ -2581,9 +2597,9 @@ describe Addressable::URI, "when parsed from " +
2581
2597
  end
2582
2598
 
2583
2599
  it "should raise an error if encoding with an unexpected return type" do
2584
- expect(lambda do
2600
+ expect do
2585
2601
  Addressable::URI.normalized_encode(@uri, Integer)
2586
- end).to raise_error(TypeError)
2602
+ end.to raise_error(TypeError)
2587
2603
  end
2588
2604
 
2589
2605
  it "if percent encoded should be 'http://example.com/C%25CC%25A7'" do
@@ -2599,9 +2615,9 @@ describe Addressable::URI, "when parsed from " +
2599
2615
  end
2600
2616
 
2601
2617
  it "should raise an error if encoding with an unexpected return type" do
2602
- expect(lambda do
2618
+ expect do
2603
2619
  Addressable::URI.encode(@uri, Integer)
2604
- end).to raise_error(TypeError)
2620
+ end.to raise_error(TypeError)
2605
2621
  end
2606
2622
 
2607
2623
  it "should be identical to its duplicate" do
@@ -2736,9 +2752,9 @@ describe Addressable::URI, "when parsed from " +
2736
2752
 
2737
2753
  it "should not be roughly equal to the string " +
2738
2754
  "'http://example.com:bogus/'" do
2739
- expect(lambda do
2755
+ expect do
2740
2756
  expect(@uri === "http://example.com:bogus/").to eq(false)
2741
- end).not_to raise_error
2757
+ end.not_to raise_error
2742
2758
  end
2743
2759
 
2744
2760
  it "should result in itself when joined with itself" do
@@ -3084,9 +3100,9 @@ describe Addressable::URI, "when parsed from " +
3084
3100
  end
3085
3101
 
3086
3102
  it "should become invalid when normalized" do
3087
- expect(lambda do
3103
+ expect do
3088
3104
  @uri.normalize
3089
- end).to raise_error(Addressable::URI::InvalidURIError, /authority/)
3105
+ end.to raise_error(Addressable::URI::InvalidURIError, /authority/)
3090
3106
  end
3091
3107
 
3092
3108
  it "should have a path of '/..//example.com'" do
@@ -3324,12 +3340,12 @@ describe Addressable::URI, "when parsed from " +
3324
3340
  end
3325
3341
 
3326
3342
  it "should raise an error if routing is attempted" do
3327
- expect(lambda do
3343
+ expect do
3328
3344
  @uri.route_to("http://example.com/")
3329
- end).to raise_error(ArgumentError, /relative\/path\/to\/resource/)
3330
- expect(lambda do
3345
+ end.to raise_error(ArgumentError, /relative\/path\/to\/resource/)
3346
+ expect do
3331
3347
  @uri.route_from("http://example.com/")
3332
- end).to raise_error(ArgumentError, /relative\/path\/to\/resource/)
3348
+ end.to raise_error(ArgumentError, /relative\/path\/to\/resource/)
3333
3349
  end
3334
3350
 
3335
3351
  it "when joined with 'another/relative/path' should be " +
@@ -3926,9 +3942,9 @@ describe Addressable::URI, "when parsed from " +
3926
3942
  end
3927
3943
 
3928
3944
  it "should raise an error if assigning a bogus object to the hostname" do
3929
- expect(lambda do
3945
+ expect do
3930
3946
  @uri.hostname = Object.new
3931
- end).to raise_error
3947
+ end.to raise_error(TypeError)
3932
3948
  end
3933
3949
 
3934
3950
  it "should have the correct port after assignment" do
@@ -4007,9 +4023,9 @@ describe Addressable::URI, "when parsed from " +
4007
4023
  end
4008
4024
 
4009
4025
  it "should raise an error if query values are set to a bogus type" do
4010
- expect(lambda do
4026
+ expect do
4011
4027
  @uri.query_values = "bogus"
4012
- end).to raise_error(TypeError)
4028
+ end.to raise_error(TypeError)
4013
4029
  end
4014
4030
 
4015
4031
  it "should have the correct fragment after assignment" do
@@ -4081,39 +4097,39 @@ describe Addressable::URI, "when parsed from " +
4081
4097
  end
4082
4098
 
4083
4099
  it "should fail to merge with bogus values" do
4084
- expect(lambda do
4100
+ expect do
4085
4101
  @uri.merge(:port => "bogus")
4086
- end).to raise_error(Addressable::URI::InvalidURIError)
4102
+ end.to raise_error(Addressable::URI::InvalidURIError)
4087
4103
  end
4088
4104
 
4089
4105
  it "should fail to merge with bogus values" do
4090
- expect(lambda do
4106
+ expect do
4091
4107
  @uri.merge(:authority => "bar@baz:bogus")
4092
- end).to raise_error(Addressable::URI::InvalidURIError)
4108
+ end.to raise_error(Addressable::URI::InvalidURIError)
4093
4109
  end
4094
4110
 
4095
4111
  it "should fail to merge with bogus parameters" do
4096
- expect(lambda do
4112
+ expect do
4097
4113
  @uri.merge(42)
4098
- end).to raise_error(TypeError)
4114
+ end.to raise_error(TypeError)
4099
4115
  end
4100
4116
 
4101
4117
  it "should fail to merge with bogus parameters" do
4102
- expect(lambda do
4118
+ expect do
4103
4119
  @uri.merge("http://example.com/")
4104
- end).to raise_error(TypeError)
4120
+ end.to raise_error(TypeError)
4105
4121
  end
4106
4122
 
4107
4123
  it "should fail to merge with both authority and subcomponents" do
4108
- expect(lambda do
4124
+ expect do
4109
4125
  @uri.merge(:authority => "foo:bar@baz:42", :port => "42")
4110
- end).to raise_error(ArgumentError)
4126
+ end.to raise_error(ArgumentError)
4111
4127
  end
4112
4128
 
4113
4129
  it "should fail to merge with both userinfo and subcomponents" do
4114
- expect(lambda do
4130
+ expect do
4115
4131
  @uri.merge(:userinfo => "foo:bar", :user => "foo")
4116
- end).to raise_error(ArgumentError)
4132
+ end.to raise_error(ArgumentError)
4117
4133
  end
4118
4134
 
4119
4135
  it "should be identical to its duplicate" do
@@ -4246,6 +4262,36 @@ describe Addressable::URI, "when parsed from " +
4246
4262
  end
4247
4263
  end
4248
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
+
4249
4295
  describe Addressable::URI, "when parsed from " +
4250
4296
  "'http://example.com/?q=a%2bb'" do
4251
4297
  before do
@@ -4287,6 +4333,46 @@ describe Addressable::URI, "when parsed from " +
4287
4333
  end
4288
4334
  end
4289
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
+
4290
4376
  describe Addressable::URI, "when parsed from " +
4291
4377
  "'http://example.com/sound%2bvision'" do
4292
4378
  before do
@@ -4398,10 +4484,10 @@ describe Addressable::URI, "when parsed from " +
4398
4484
  end
4399
4485
 
4400
4486
  it "should raise an error after nil assignment of authority segment" do
4401
- expect(lambda do
4487
+ expect do
4402
4488
  # This would create an invalid URI
4403
4489
  @uri.authority = nil
4404
- end).to raise_error
4490
+ end.to raise_error(Addressable::URI::InvalidURIError)
4405
4491
  end
4406
4492
  end
4407
4493
 
@@ -4630,12 +4716,12 @@ describe Addressable::URI, "when parsed from " +
4630
4716
  end
4631
4717
 
4632
4718
  it "should raise an error if routing is attempted" do
4633
- expect(lambda do
4719
+ expect do
4634
4720
  @uri.route_to("http://example.com/")
4635
- end).to raise_error(ArgumentError, /\/\/example.com\//)
4636
- expect(lambda do
4721
+ end.to raise_error(ArgumentError, /\/\/example.com\//)
4722
+ expect do
4637
4723
  @uri.route_from("http://example.com/")
4638
- end).to raise_error(ArgumentError, /\/\/example.com\//)
4724
+ end.to raise_error(ArgumentError, /\/\/example.com\//)
4639
4725
  end
4640
4726
 
4641
4727
  it "should have a 'null' origin" do
@@ -4729,9 +4815,9 @@ end
4729
4815
  describe Addressable::URI, "when parsed from " +
4730
4816
  "'http://under_score.example.com/'" do
4731
4817
  it "should not cause an error" do
4732
- expect(lambda do
4818
+ expect do
4733
4819
  Addressable::URI.parse("http://under_score.example.com/")
4734
- end).not_to raise_error
4820
+ end.not_to raise_error
4735
4821
  end
4736
4822
  end
4737
4823
 
@@ -4803,9 +4889,9 @@ describe Addressable::URI, "when parsed from '?one=1&two=2&three=3'" do
4803
4889
  end
4804
4890
 
4805
4891
  it "should raise an error for invalid return type values" do
4806
- expect(lambda do
4807
- @uri.query_values(Fixnum)
4808
- end).to raise_error(ArgumentError)
4892
+ expect do
4893
+ @uri.query_values(Integer)
4894
+ end.to raise_error(ArgumentError)
4809
4895
  end
4810
4896
 
4811
4897
  it "should have the correct array query values" do
@@ -5406,9 +5492,9 @@ describe Addressable::URI, "with a base uri of 'http://a/b/c/d;p?q'" do
5406
5492
  end
5407
5493
 
5408
5494
  it "when joined with a bogus object a TypeError should be raised" do
5409
- expect(lambda do
5495
+ expect do
5410
5496
  Addressable::URI.join(@uri, 42)
5411
- end).to raise_error(TypeError)
5497
+ end.to raise_error(TypeError)
5412
5498
  end
5413
5499
  end
5414
5500
 
@@ -5435,9 +5521,9 @@ end
5435
5521
 
5436
5522
  describe Addressable::URI, "when converting a bogus path" do
5437
5523
  it "should raise a TypeError" do
5438
- expect(lambda do
5524
+ expect do
5439
5525
  Addressable::URI.convert_path(42)
5440
- end).to raise_error(TypeError)
5526
+ end.to raise_error(TypeError)
5441
5527
  end
5442
5528
  end
5443
5529
 
@@ -5490,6 +5576,31 @@ describe Addressable::URI, "when given the path '/one/two/'" do
5490
5576
  end
5491
5577
  end
5492
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
+
5493
5604
  describe Addressable::URI, "when given the path " +
5494
5605
  "'c:\\windows\\My Documents 100%20\\foo.txt'" do
5495
5606
  before do
@@ -5607,9 +5718,9 @@ describe Addressable::URI, "when parsing a non-String object" do
5607
5718
  end
5608
5719
 
5609
5720
  it "should raise a TypeError for objects than cannot be converted" do
5610
- expect(lambda do
5721
+ expect do
5611
5722
  Addressable::URI.parse(42)
5612
- end).to raise_error(TypeError)
5723
+ end.to raise_error(TypeError)
5613
5724
  end
5614
5725
 
5615
5726
  it "should correctly parse heuristically anything with a 'to_str' method" do
@@ -5617,9 +5728,9 @@ describe Addressable::URI, "when parsing a non-String object" do
5617
5728
  end
5618
5729
 
5619
5730
  it "should raise a TypeError for objects than cannot be converted" do
5620
- expect(lambda do
5731
+ expect do
5621
5732
  Addressable::URI.heuristic_parse(42)
5622
- end).to raise_error(TypeError)
5733
+ end.to raise_error(TypeError)
5623
5734
  end
5624
5735
  end
5625
5736
 
@@ -5663,9 +5774,9 @@ end
5663
5774
 
5664
5775
  describe Addressable::URI, "when form encoding a non-Array object" do
5665
5776
  it "should raise a TypeError for objects than cannot be converted" do
5666
- expect(lambda do
5777
+ expect do
5667
5778
  Addressable::URI.form_encode(42)
5668
- end).to raise_error(TypeError)
5779
+ end.to raise_error(TypeError)
5669
5780
  end
5670
5781
  end
5671
5782
 
@@ -5731,9 +5842,9 @@ describe Addressable::URI, "when form unencoding a non-String object" do
5731
5842
  end
5732
5843
 
5733
5844
  it "should raise a TypeError for objects than cannot be converted" do
5734
- expect(lambda do
5845
+ expect do
5735
5846
  Addressable::URI.form_unencode(42)
5736
- end).to raise_error(TypeError)
5847
+ end.to raise_error(TypeError)
5737
5848
  end
5738
5849
  end
5739
5850
 
@@ -5743,15 +5854,15 @@ describe Addressable::URI, "when normalizing a non-String object" do
5743
5854
  end
5744
5855
 
5745
5856
  it "should raise a TypeError for objects than cannot be converted" do
5746
- expect(lambda do
5857
+ expect do
5747
5858
  Addressable::URI.normalize_component(42)
5748
- end).to raise_error(TypeError)
5859
+ end.to raise_error(TypeError)
5749
5860
  end
5750
5861
 
5751
5862
  it "should raise a TypeError for objects than cannot be converted" do
5752
- expect(lambda do
5863
+ expect do
5753
5864
  Addressable::URI.normalize_component("component", 42)
5754
- end).to raise_error(TypeError)
5865
+ end.to raise_error(TypeError)
5755
5866
  end
5756
5867
  end
5757
5868
 
@@ -5823,6 +5934,18 @@ describe Addressable::URI, "when normalizing a string but leaving some character
5823
5934
  end
5824
5935
  end
5825
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
+
5826
5949
  describe Addressable::URI, "when encoding a string with existing encodings to upcase" do
5827
5950
  it "should result in correct percent encoded sequence" do
5828
5951
  expect(Addressable::URI.encode_component("JK%4c", "0-9A-IKM-Za-z%", "L")).to eq("%4AK%4C")
@@ -5895,41 +6018,41 @@ end
5895
6018
 
5896
6019
  describe Addressable::URI, "when unencoding a bogus object" do
5897
6020
  it "should raise a TypeError" do
5898
- expect(lambda do
6021
+ expect do
5899
6022
  Addressable::URI.unencode_component(42)
5900
- end).to raise_error(TypeError)
6023
+ end.to raise_error(TypeError)
5901
6024
  end
5902
6025
 
5903
6026
  it "should raise a TypeError" do
5904
- expect(lambda do
6027
+ expect do
5905
6028
  Addressable::URI.unencode("/path?g%C3%BCnther", Integer)
5906
- end).to raise_error(TypeError)
6029
+ end.to raise_error(TypeError)
5907
6030
  end
5908
6031
  end
5909
6032
 
5910
6033
  describe Addressable::URI, "when encoding a bogus object" do
5911
6034
  it "should raise a TypeError" do
5912
- expect(lambda do
6035
+ expect do
5913
6036
  Addressable::URI.encode(Object.new)
5914
- end).to raise_error(TypeError)
6037
+ end.to raise_error(TypeError)
5915
6038
  end
5916
6039
 
5917
6040
  it "should raise a TypeError" do
5918
- expect(lambda do
6041
+ expect do
5919
6042
  Addressable::URI.normalized_encode(Object.new)
5920
- end).to raise_error(TypeError)
6043
+ end.to raise_error(TypeError)
5921
6044
  end
5922
6045
 
5923
6046
  it "should raise a TypeError" do
5924
- expect(lambda do
6047
+ expect do
5925
6048
  Addressable::URI.encode_component("günther", Object.new)
5926
- end).to raise_error(TypeError)
6049
+ end.to raise_error(TypeError)
5927
6050
  end
5928
6051
 
5929
6052
  it "should raise a TypeError" do
5930
- expect(lambda do
6053
+ expect do
5931
6054
  Addressable::URI.encode_component(Object.new)
5932
- end).to raise_error(TypeError)
6055
+ end.to raise_error(TypeError)
5933
6056
  end
5934
6057
  end
5935
6058
 
@@ -5945,9 +6068,9 @@ describe Addressable::URI, "when given the input " +
5945
6068
  end
5946
6069
 
5947
6070
  it "should not raise error when frozen" do
5948
- expect(lambda do
6071
+ expect do
5949
6072
  Addressable::URI.heuristic_parse(@input).freeze.to_s
5950
- end).not_to raise_error
6073
+ end.not_to raise_error
5951
6074
  end
5952
6075
  end
5953
6076
 
@@ -6227,6 +6350,18 @@ describe Addressable::URI, "when given the input " +
6227
6350
  end
6228
6351
  end
6229
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
+
6230
6365
  describe Addressable::URI, "when given the input " +
6231
6366
  "'feed:///example.com'" do
6232
6367
  before do
@@ -6239,6 +6374,18 @@ describe Addressable::URI, "when given the input " +
6239
6374
  end
6240
6375
  end
6241
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
+
6242
6389
  describe Addressable::URI, "when given the input " +
6243
6390
  "'file://path/to/resource/'" do
6244
6391
  before do
@@ -6251,6 +6398,18 @@ describe Addressable::URI, "when given the input " +
6251
6398
  end
6252
6399
  end
6253
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
+
6254
6413
  describe Addressable::URI, "when given the input " +
6255
6414
  "'feed://http://example.com'" do
6256
6415
  before do
@@ -6275,6 +6434,44 @@ describe Addressable::URI, "when given the input " +
6275
6434
  end
6276
6435
  end
6277
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
+
6278
6475
  describe Addressable::URI, "when assigning query values" do
6279
6476
  before do
6280
6477
  @uri = Addressable::URI.new
@@ -6286,54 +6483,54 @@ describe Addressable::URI, "when assigning query values" do
6286
6483
  end
6287
6484
 
6288
6485
  it "should raise an error attempting to assign {'a' => {'b' => ['c']}}" do
6289
- expect(lambda do
6486
+ expect do
6290
6487
  @uri.query_values = { 'a' => {'b' => ['c'] } }
6291
- end).to raise_error(TypeError)
6488
+ end.to raise_error(TypeError)
6292
6489
  end
6293
6490
 
6294
6491
  it "should raise an error attempting to assign " +
6295
6492
  "{:b => '2', :a => {:c => '1'}}" do
6296
- expect(lambda do
6493
+ expect do
6297
6494
  @uri.query_values = {:b => '2', :a => {:c => '1'}}
6298
- end).to raise_error(TypeError)
6495
+ end.to raise_error(TypeError)
6299
6496
  end
6300
6497
 
6301
6498
  it "should raise an error attempting to assign " +
6302
6499
  "{:a => 'a', :b => [{:c => 'c', :d => 'd'}, " +
6303
6500
  "{:e => 'e', :f => 'f'}]}" do
6304
- expect(lambda do
6501
+ expect do
6305
6502
  @uri.query_values = {
6306
6503
  :a => "a", :b => [{:c => "c", :d => "d"}, {:e => "e", :f => "f"}]
6307
6504
  }
6308
- end).to raise_error(TypeError)
6505
+ end.to raise_error(TypeError)
6309
6506
  end
6310
6507
 
6311
6508
  it "should raise an error attempting to assign " +
6312
6509
  "{:a => 'a', :b => [{:c => true, :d => 'd'}, " +
6313
6510
  "{:e => 'e', :f => 'f'}]}" do
6314
- expect(lambda do
6511
+ expect do
6315
6512
  @uri.query_values = {
6316
6513
  :a => 'a', :b => [{:c => true, :d => 'd'}, {:e => 'e', :f => 'f'}]
6317
6514
  }
6318
- end).to raise_error(TypeError)
6515
+ end.to raise_error(TypeError)
6319
6516
  end
6320
6517
 
6321
6518
  it "should raise an error attempting to assign " +
6322
6519
  "{:a => 'a', :b => {:c => true, :d => 'd'}}" do
6323
- expect(lambda do
6520
+ expect do
6324
6521
  @uri.query_values = {
6325
6522
  :a => 'a', :b => {:c => true, :d => 'd'}
6326
6523
  }
6327
- end).to raise_error(TypeError)
6524
+ end.to raise_error(TypeError)
6328
6525
  end
6329
6526
 
6330
6527
  it "should raise an error attempting to assign " +
6331
6528
  "{:a => 'a', :b => {:c => true, :d => 'd'}}" do
6332
- expect(lambda do
6529
+ expect do
6333
6530
  @uri.query_values = {
6334
6531
  :a => 'a', :b => {:c => true, :d => 'd'}
6335
6532
  }
6336
- end).to raise_error(TypeError)
6533
+ end.to raise_error(TypeError)
6337
6534
  end
6338
6535
 
6339
6536
  it "should correctly assign {:a => 1, :b => 1.5}" do
@@ -6344,13 +6541,13 @@ describe Addressable::URI, "when assigning query values" do
6344
6541
  it "should raise an error attempting to assign " +
6345
6542
  "{:z => 1, :f => [2, {999.1 => [3,'4']}, ['h', 'i']], " +
6346
6543
  ":a => {:b => ['c', 'd'], :e => true, :y => 0.5}}" do
6347
- expect(lambda do
6544
+ expect do
6348
6545
  @uri.query_values = {
6349
6546
  :z => 1,
6350
6547
  :f => [ 2, {999.1 => [3,'4']}, ['h', 'i'] ],
6351
6548
  :a => { :b => ['c', 'd'], :e => true, :y => 0.5 }
6352
6549
  }
6353
- end).to raise_error(TypeError)
6550
+ end.to raise_error(TypeError)
6354
6551
  end
6355
6552
 
6356
6553
  it "should correctly assign {}" do
@@ -6400,7 +6597,7 @@ describe Addressable::URI, "when assigning path values" do
6400
6597
  @uri.path = "acct:bob@sporkmonger.com"
6401
6598
  expect(@uri.path).to eq("acct:bob@sporkmonger.com")
6402
6599
  expect(@uri.normalize.to_str).to eq("acct%2Fbob@sporkmonger.com")
6403
- expect(lambda { @uri.to_s }).to raise_error(
6600
+ expect { @uri.to_s }.to raise_error(
6404
6601
  Addressable::URI::InvalidURIError
6405
6602
  )
6406
6603
  end
@@ -6418,26 +6615,26 @@ describe Addressable::URI, "when assigning path values" do
6418
6615
  end
6419
6616
 
6420
6617
  it "should not allow relative paths to be assigned on absolute URIs" do
6421
- expect(lambda do
6618
+ expect do
6422
6619
  @uri.scheme = "http"
6423
6620
  @uri.host = "example.com"
6424
6621
  @uri.path = "acct:bob@sporkmonger.com"
6425
- end).to raise_error(Addressable::URI::InvalidURIError)
6622
+ end.to raise_error(Addressable::URI::InvalidURIError)
6426
6623
  end
6427
6624
 
6428
6625
  it "should not allow relative paths to be assigned on absolute URIs" do
6429
- expect(lambda do
6626
+ expect do
6430
6627
  @uri.path = "acct:bob@sporkmonger.com"
6431
6628
  @uri.scheme = "http"
6432
6629
  @uri.host = "example.com"
6433
- end).to raise_error(Addressable::URI::InvalidURIError)
6630
+ end.to raise_error(Addressable::URI::InvalidURIError)
6434
6631
  end
6435
6632
 
6436
6633
  it "should not allow relative paths to be assigned on absolute URIs" do
6437
- expect(lambda do
6634
+ expect do
6438
6635
  @uri.path = "uuid:0b3ecf60-3f93-11df-a9c3-001f5bfffe12"
6439
6636
  @uri.scheme = "urn"
6440
- end).not_to raise_error
6637
+ end.not_to raise_error
6441
6638
  end
6442
6639
  end
6443
6640