addressable 2.5.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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # encoding:utf-8
2
4
  #--
3
5
  # Copyright (C) Bob Aman
@@ -21,7 +23,7 @@ if !defined?(Addressable::VERSION)
21
23
  module Addressable
22
24
  module VERSION
23
25
  MAJOR = 2
24
- MINOR = 5
26
+ MINOR = 8
25
27
  TINY = 0
26
28
 
27
29
  STRING = [MAJOR, MINOR, TINY].join('.')
@@ -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
@@ -134,6 +136,12 @@ shared_examples_for "converting from unicode to ASCII" do
134
136
  )).to eq("xn--4ud")
135
137
  end
136
138
 
139
+ it "should convert '🌹🌹🌹.ws' correctly" do
140
+ expect(Addressable::IDNA.to_ascii(
141
+ "\360\237\214\271\360\237\214\271\360\237\214\271.ws"
142
+ )).to eq("xn--2h8haa.ws")
143
+ end
144
+
137
145
  it "should handle two adjacent '.'s correctly" do
138
146
  expect(Addressable::IDNA.to_ascii(
139
147
  "example..host"
@@ -142,9 +150,9 @@ shared_examples_for "converting from unicode to ASCII" do
142
150
  end
143
151
 
144
152
  shared_examples_for "converting from ASCII to unicode" do
145
- LONG = 'AcinusFallumTrompetumNullunCreditumVisumEstAtCuadLongumEtCefallum.com'
146
- it "should convert '#{LONG}' correctly" do
147
- 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)
148
156
  end
149
157
 
150
158
  it "should return the identity conversion when punycode decode fails" do
@@ -231,6 +239,12 @@ shared_examples_for "converting from ASCII to unicode" do
231
239
  )).to eq("\341\206\265")
232
240
  end
233
241
 
242
+ it "should convert '🌹🌹🌹.ws' correctly" do
243
+ expect(Addressable::IDNA.to_unicode(
244
+ "xn--2h8haa.ws"
245
+ )).to eq("\360\237\214\271\360\237\214\271\360\237\214\271.ws")
246
+ end
247
+
234
248
  it "should handle two adjacent '.'s correctly" do
235
249
  expect(Addressable::IDNA.to_unicode(
236
250
  "example..host"
@@ -280,7 +294,9 @@ begin
280
294
  it_should_behave_like "converting from unicode to ASCII"
281
295
  it_should_behave_like "converting from ASCII to unicode"
282
296
  end
283
- rescue LoadError
297
+ rescue LoadError => error
298
+ raise error if ENV["CI"] && TestHelper.native_supported?
299
+
284
300
  # Cannot test the native implementation without libidn support.
285
301
  warn('Could not load native IDN implementation.')
286
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
 
@@ -91,7 +94,7 @@ describe "Type conversion" do
91
94
  '{hello}' => '1234',
92
95
  '{nothing}' => '',
93
96
  '{sym}' => 'symbolic',
94
- '{decimal}' => '0.1E1'
97
+ '{decimal}' => RUBY_VERSION < '2.4.0' ? '0.1E1' : '0.1e1'
95
98
  }
96
99
  end
97
100
 
@@ -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}/")
@@ -969,6 +1002,24 @@ describe Addressable::Template do
969
1002
  )
970
1003
  end
971
1004
  end
1005
+ context "partial expand with unicode values" do
1006
+ subject do
1007
+ Addressable::Template.new("http://example.com/{resource}/{query}/")
1008
+ end
1009
+ it "normalizes unicode by default" do
1010
+ template = subject.partial_expand("query" => "Cafe\u0301")
1011
+ expect(template.pattern).to eq(
1012
+ "http://example.com/{resource}/Caf%C3%A9/"
1013
+ )
1014
+ end
1015
+
1016
+ it "does not normalize unicode when byte semantics requested" do
1017
+ template = subject.partial_expand({"query" => "Cafe\u0301"}, nil, false)
1018
+ expect(template.pattern).to eq(
1019
+ "http://example.com/{resource}/Cafe%CC%81/"
1020
+ )
1021
+ end
1022
+ end
972
1023
  end
973
1024
  describe "Partial expand with strings" do
974
1025
  context "partial_expand with two simple values" do
@@ -1013,6 +1064,20 @@ describe Addressable::Template do
1013
1064
  end
1014
1065
  end
1015
1066
  describe "Expand" do
1067
+ context "expand with unicode values" do
1068
+ subject do
1069
+ Addressable::Template.new("http://example.com/search/{query}/")
1070
+ end
1071
+ it "normalizes unicode by default" do
1072
+ uri = subject.expand("query" => "Cafe\u0301").to_str
1073
+ expect(uri).to eq("http://example.com/search/Caf%C3%A9/")
1074
+ end
1075
+
1076
+ it "does not normalize unicode when byte semantics requested" do
1077
+ uri = subject.expand({ "query" => "Cafe\u0301" }, nil, false).to_str
1078
+ expect(uri).to eq("http://example.com/search/Cafe%CC%81/")
1079
+ end
1080
+ end
1016
1081
  context "expand with a processor" do
1017
1082
  subject {
1018
1083
  Addressable::Template.new("http://example.com/search/{query}/")
@@ -1276,6 +1341,14 @@ describe Addressable::Template do
1276
1341
  expect(subject).not_to match("foo_bar*")
1277
1342
  expect(subject).not_to match("foo_bar:20")
1278
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
1279
1352
  end
1280
1353
  context "VARIABLE_LIST" do
1281
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,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)
117
- end
118
- end
119
-
120
- describe Addressable::URI, "when created with a non-string authority" do
121
- it "should raise an error" do
122
- expect(lambda do
123
- Addressable::URI.new(:authority => :bogus)
124
- end).to raise_error(TypeError)
118
+ end.to raise_error(TypeError)
125
119
  end
126
120
  end
127
121
 
128
122
  describe Addressable::URI, "when created with a non-string authority" do
129
123
  it "should raise an error" do
130
- expect(lambda do
124
+ expect do
131
125
  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
 
@@ -963,6 +957,10 @@ describe Addressable::URI, "when frozen" do
963
957
  expect(@uri.normalize.query).to eq("a=1")
964
958
  end
965
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
+
966
964
  it "returns '1%323' for #fragment" do
967
965
  expect(@uri.fragment).to eq("1%323")
968
966
  end
@@ -1017,31 +1015,31 @@ describe Addressable::URI, "when created from string components" do
1017
1015
  end
1018
1016
 
1019
1017
  it "should raise an error if invalid components omitted" do
1020
- expect(lambda do
1018
+ expect do
1021
1019
  @uri.omit(:bogus)
1022
- end).to raise_error(ArgumentError)
1023
- expect(lambda do
1020
+ end.to raise_error(ArgumentError)
1021
+ expect do
1024
1022
  @uri.omit(:scheme, :bogus, :path)
1025
- end).to raise_error(ArgumentError)
1023
+ end.to raise_error(ArgumentError)
1026
1024
  end
1027
1025
  end
1028
1026
 
1029
1027
  describe Addressable::URI, "when created with a nil host but " +
1030
1028
  "non-nil authority components" do
1031
1029
  it "should raise an error" do
1032
- expect(lambda do
1030
+ expect do
1033
1031
  Addressable::URI.new(:user => "user", :password => "pass", :port => 80)
1034
- end).to raise_error(Addressable::URI::InvalidURIError)
1032
+ end.to raise_error(Addressable::URI::InvalidURIError)
1035
1033
  end
1036
1034
  end
1037
1035
 
1038
1036
  describe Addressable::URI, "when created with both an authority and a user" do
1039
1037
  it "should raise an error" do
1040
- expect(lambda do
1038
+ expect do
1041
1039
  Addressable::URI.new(
1042
1040
  :user => "user", :authority => "user@example.com:80"
1043
1041
  )
1044
- end).to raise_error(ArgumentError)
1042
+ end.to raise_error(ArgumentError)
1045
1043
  end
1046
1044
  end
1047
1045
 
@@ -1079,33 +1077,33 @@ end
1079
1077
 
1080
1078
  describe Addressable::URI, "when created with a host with a backslash" do
1081
1079
  it "should raise an error" do
1082
- expect(lambda do
1080
+ expect do
1083
1081
  Addressable::URI.new(:authority => "example\\example")
1084
- end).to raise_error(Addressable::URI::InvalidURIError)
1082
+ end.to raise_error(Addressable::URI::InvalidURIError)
1085
1083
  end
1086
1084
  end
1087
1085
 
1088
1086
  describe Addressable::URI, "when created with a host with a slash" do
1089
1087
  it "should raise an error" do
1090
- expect(lambda do
1088
+ expect do
1091
1089
  Addressable::URI.new(:authority => "example/example")
1092
- end).to raise_error(Addressable::URI::InvalidURIError)
1090
+ end.to raise_error(Addressable::URI::InvalidURIError)
1093
1091
  end
1094
1092
  end
1095
1093
 
1096
1094
  describe Addressable::URI, "when created with a host with a space" do
1097
1095
  it "should raise an error" do
1098
- expect(lambda do
1096
+ expect do
1099
1097
  Addressable::URI.new(:authority => "example example")
1100
- end).to raise_error(Addressable::URI::InvalidURIError)
1098
+ end.to raise_error(Addressable::URI::InvalidURIError)
1101
1099
  end
1102
1100
  end
1103
1101
 
1104
1102
  describe Addressable::URI, "when created with both a userinfo and a user" do
1105
1103
  it "should raise an error" do
1106
- expect(lambda do
1104
+ expect do
1107
1105
  Addressable::URI.new(:user => "user", :userinfo => "user:pass")
1108
- end).to raise_error(ArgumentError)
1106
+ end.to raise_error(ArgumentError)
1109
1107
  end
1110
1108
  end
1111
1109
 
@@ -1197,18 +1195,18 @@ describe Addressable::URI, "when parsed from something that looks " +
1197
1195
  "like a URI object" do
1198
1196
  it "should parse without error" do
1199
1197
  uri = Addressable::URI.parse(Fake::URI::HTTP.new("http://example.com/"))
1200
- expect(lambda do
1198
+ expect do
1201
1199
  Addressable::URI.parse(uri)
1202
- end).not_to raise_error
1200
+ end.not_to raise_error
1203
1201
  end
1204
1202
  end
1205
1203
 
1206
1204
  describe Addressable::URI, "when parsed from a standard library URI object" do
1207
1205
  it "should parse without error" do
1208
1206
  uri = Addressable::URI.parse(URI.parse("http://example.com/"))
1209
- expect(lambda do
1207
+ expect do
1210
1208
  Addressable::URI.parse(uri)
1211
- end).not_to raise_error
1209
+ end.not_to raise_error
1212
1210
  end
1213
1211
  end
1214
1212
 
@@ -1368,9 +1366,9 @@ describe Addressable::URI, "when parsed from " +
1368
1366
  end
1369
1367
 
1370
1368
  it "should not allow request URI assignment" do
1371
- expect(lambda do
1369
+ expect do
1372
1370
  @uri.request_uri = "/"
1373
- end).to raise_error(Addressable::URI::InvalidURIError)
1371
+ end.to raise_error(Addressable::URI::InvalidURIError)
1374
1372
  end
1375
1373
 
1376
1374
  it "should have a query of 'objectClass?one'" do
@@ -1392,9 +1390,9 @@ describe Addressable::URI, "when parsed from " +
1392
1390
  end
1393
1391
 
1394
1392
  it "should raise an error if omission would create an invalid URI" do
1395
- expect(lambda do
1393
+ expect do
1396
1394
  @uri.omit(:authority, :path)
1397
- end).to raise_error(Addressable::URI::InvalidURIError)
1395
+ end.to raise_error(Addressable::URI::InvalidURIError)
1398
1396
  end
1399
1397
 
1400
1398
  it "should have an origin of 'ldap://[2001:db8::7]'" do
@@ -1780,9 +1778,9 @@ describe Addressable::URI, "when parsed from " +
1780
1778
 
1781
1779
  it "should not be roughly equal to the string " +
1782
1780
  "'http://example.com:bogus/'" do
1783
- expect(lambda do
1781
+ expect do
1784
1782
  expect(@uri === "http://example.com:bogus/").to eq(false)
1785
- end).not_to raise_error
1783
+ end.not_to raise_error
1786
1784
  end
1787
1785
 
1788
1786
  it "should result in itself when joined with itself" do
@@ -1812,21 +1810,21 @@ describe Addressable::URI, "when parsed from " +
1812
1810
  end
1813
1811
 
1814
1812
  it "should not allow origin assignment without scheme" do
1815
- expect(lambda do
1813
+ expect do
1816
1814
  @uri.origin = "example.com"
1817
- end).to raise_error(Addressable::URI::InvalidURIError)
1815
+ end.to raise_error(Addressable::URI::InvalidURIError)
1818
1816
  end
1819
1817
 
1820
1818
  it "should not allow origin assignment without host" do
1821
- expect(lambda do
1819
+ expect do
1822
1820
  @uri.origin = "http://"
1823
- end).to raise_error(Addressable::URI::InvalidURIError)
1821
+ end.to raise_error(Addressable::URI::InvalidURIError)
1824
1822
  end
1825
1823
 
1826
1824
  it "should not allow origin assignment with bogus type" do
1827
- expect(lambda do
1825
+ expect do
1828
1826
  @uri.origin = :bogus
1829
- end).to raise_error(TypeError)
1827
+ end.to raise_error(TypeError)
1830
1828
  end
1831
1829
 
1832
1830
  # Section 6.2.3 of RFC 3986
@@ -1882,9 +1880,9 @@ describe Addressable::URI, "when parsed from " +
1882
1880
  end
1883
1881
 
1884
1882
  it "when joined with a bogus object a TypeError should be raised" do
1885
- expect(lambda do
1883
+ expect do
1886
1884
  @uri.join(42)
1887
- end).to raise_error(TypeError)
1885
+ end.to raise_error(TypeError)
1888
1886
  end
1889
1887
 
1890
1888
  it "should have the correct username after assignment" do
@@ -1979,15 +1977,29 @@ end
1979
1977
 
1980
1978
  # Section 5.1.2 of RFC 2616
1981
1979
  describe Addressable::URI, "when parsed from " +
1982
- "'http://www.w3.org/pub/WWW/TheProject.html'" do
1980
+ "'HTTP://www.w3.org/pub/WWW/TheProject.html'" do
1983
1981
  before do
1984
- @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")
1985
1983
  end
1986
1984
 
1987
1985
  it "should have the correct request URI" do
1988
1986
  expect(@uri.request_uri).to eq("/pub/WWW/TheProject.html")
1989
1987
  end
1990
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
+
1991
2003
  it "should have the correct request URI after assignment" do
1992
2004
  @uri.request_uri = "/some/where/else.html?query?string"
1993
2005
  expect(@uri.request_uri).to eq("/some/where/else.html?query?string")
@@ -2003,20 +2015,20 @@ describe Addressable::URI, "when parsed from " +
2003
2015
  end
2004
2016
 
2005
2017
  it "should raise an error if the site value is set to something bogus" do
2006
- expect(lambda do
2018
+ expect do
2007
2019
  @uri.site = 42
2008
- end).to raise_error(TypeError)
2020
+ end.to raise_error(TypeError)
2009
2021
  end
2010
2022
 
2011
2023
  it "should raise an error if the request URI is set to something bogus" do
2012
- expect(lambda do
2024
+ expect do
2013
2025
  @uri.request_uri = 42
2014
- end).to raise_error(TypeError)
2026
+ end.to raise_error(TypeError)
2015
2027
  end
2016
2028
 
2017
2029
  it "should correctly convert to a hash" do
2018
2030
  expect(@uri.to_hash).to eq({
2019
- :scheme => "http",
2031
+ :scheme => "HTTP",
2020
2032
  :user => nil,
2021
2033
  :password => nil,
2022
2034
  :host => "www.w3.org",
@@ -2060,9 +2072,9 @@ describe Addressable::URI, "when parsing IPv6 addresses" do
2060
2072
 
2061
2073
  it "should raise an error for " +
2062
2074
  "'http://[<invalid>]/'" do
2063
- expect(lambda do
2075
+ expect do
2064
2076
  Addressable::URI.parse("http://[<invalid>]/")
2065
- end).to raise_error(Addressable::URI::InvalidURIError)
2077
+ end.to raise_error(Addressable::URI::InvalidURIError)
2066
2078
  end
2067
2079
  end
2068
2080
 
@@ -2088,9 +2100,9 @@ describe Addressable::URI, "when assigning IPv6 address" do
2088
2100
  it "should not allow to set bare IPv6 address as host" do
2089
2101
  uri = Addressable::URI.parse("http://[::1]/")
2090
2102
  skip "not checked"
2091
- expect(lambda do
2103
+ expect do
2092
2104
  uri.host = '3ffe:1900:4545:3:200:f8ff:fe21:67cf'
2093
- end).to raise_error(Addressable::URI::InvalidURIError)
2105
+ end.to raise_error(Addressable::URI::InvalidURIError)
2094
2106
  end
2095
2107
  end
2096
2108
 
@@ -2122,9 +2134,9 @@ describe Addressable::URI, "when parsing IPvFuture addresses" do
2122
2134
 
2123
2135
  it "should raise an error for " +
2124
2136
  "'http://[v0.<invalid>]/'" do
2125
- expect(lambda do
2137
+ expect do
2126
2138
  Addressable::URI.parse("http://[v0.<invalid>]/")
2127
- end).to raise_error(Addressable::URI::InvalidURIError)
2139
+ end.to raise_error(Addressable::URI::InvalidURIError)
2128
2140
  end
2129
2141
  end
2130
2142
 
@@ -2468,9 +2480,9 @@ describe Addressable::URI, "when parsed from " +
2468
2480
  end
2469
2481
 
2470
2482
  it "should not raise an exception when normalized" do
2471
- expect(lambda do
2483
+ expect do
2472
2484
  @uri.normalize
2473
- end).not_to raise_error
2485
+ end.not_to raise_error
2474
2486
  end
2475
2487
 
2476
2488
  it "should be considered to be in normal form" do
@@ -2522,9 +2534,9 @@ describe Addressable::URI, "when parsed from " +
2522
2534
  end
2523
2535
 
2524
2536
  it "should not raise an exception when normalized" do
2525
- expect(lambda do
2537
+ expect do
2526
2538
  @uri.normalize
2527
- end).not_to raise_error
2539
+ end.not_to raise_error
2528
2540
  end
2529
2541
 
2530
2542
  it "should be considered to be in normal form" do
@@ -2547,9 +2559,9 @@ describe Addressable::URI, "when parsed from " +
2547
2559
  end
2548
2560
 
2549
2561
  it "should not raise an exception when normalized" do
2550
- expect(lambda do
2562
+ expect do
2551
2563
  @uri.normalize
2552
- end).not_to raise_error
2564
+ end.not_to raise_error
2553
2565
  end
2554
2566
 
2555
2567
  it "should be considered to be in normal form" do
@@ -2585,9 +2597,9 @@ describe Addressable::URI, "when parsed from " +
2585
2597
  end
2586
2598
 
2587
2599
  it "should raise an error if encoding with an unexpected return type" do
2588
- expect(lambda do
2600
+ expect do
2589
2601
  Addressable::URI.normalized_encode(@uri, Integer)
2590
- end).to raise_error(TypeError)
2602
+ end.to raise_error(TypeError)
2591
2603
  end
2592
2604
 
2593
2605
  it "if percent encoded should be 'http://example.com/C%25CC%25A7'" do
@@ -2603,9 +2615,9 @@ describe Addressable::URI, "when parsed from " +
2603
2615
  end
2604
2616
 
2605
2617
  it "should raise an error if encoding with an unexpected return type" do
2606
- expect(lambda do
2618
+ expect do
2607
2619
  Addressable::URI.encode(@uri, Integer)
2608
- end).to raise_error(TypeError)
2620
+ end.to raise_error(TypeError)
2609
2621
  end
2610
2622
 
2611
2623
  it "should be identical to its duplicate" do
@@ -2740,9 +2752,9 @@ describe Addressable::URI, "when parsed from " +
2740
2752
 
2741
2753
  it "should not be roughly equal to the string " +
2742
2754
  "'http://example.com:bogus/'" do
2743
- expect(lambda do
2755
+ expect do
2744
2756
  expect(@uri === "http://example.com:bogus/").to eq(false)
2745
- end).not_to raise_error
2757
+ end.not_to raise_error
2746
2758
  end
2747
2759
 
2748
2760
  it "should result in itself when joined with itself" do
@@ -3088,9 +3100,9 @@ describe Addressable::URI, "when parsed from " +
3088
3100
  end
3089
3101
 
3090
3102
  it "should become invalid when normalized" do
3091
- expect(lambda do
3103
+ expect do
3092
3104
  @uri.normalize
3093
- end).to raise_error(Addressable::URI::InvalidURIError, /authority/)
3105
+ end.to raise_error(Addressable::URI::InvalidURIError, /authority/)
3094
3106
  end
3095
3107
 
3096
3108
  it "should have a path of '/..//example.com'" do
@@ -3328,12 +3340,12 @@ describe Addressable::URI, "when parsed from " +
3328
3340
  end
3329
3341
 
3330
3342
  it "should raise an error if routing is attempted" do
3331
- expect(lambda do
3343
+ expect do
3332
3344
  @uri.route_to("http://example.com/")
3333
- end).to raise_error(ArgumentError, /relative\/path\/to\/resource/)
3334
- expect(lambda do
3345
+ end.to raise_error(ArgumentError, /relative\/path\/to\/resource/)
3346
+ expect do
3335
3347
  @uri.route_from("http://example.com/")
3336
- end).to raise_error(ArgumentError, /relative\/path\/to\/resource/)
3348
+ end.to raise_error(ArgumentError, /relative\/path\/to\/resource/)
3337
3349
  end
3338
3350
 
3339
3351
  it "when joined with 'another/relative/path' should be " +
@@ -3930,9 +3942,9 @@ describe Addressable::URI, "when parsed from " +
3930
3942
  end
3931
3943
 
3932
3944
  it "should raise an error if assigning a bogus object to the hostname" do
3933
- expect(lambda do
3945
+ expect do
3934
3946
  @uri.hostname = Object.new
3935
- end).to raise_error
3947
+ end.to raise_error(TypeError)
3936
3948
  end
3937
3949
 
3938
3950
  it "should have the correct port after assignment" do
@@ -4011,9 +4023,9 @@ describe Addressable::URI, "when parsed from " +
4011
4023
  end
4012
4024
 
4013
4025
  it "should raise an error if query values are set to a bogus type" do
4014
- expect(lambda do
4026
+ expect do
4015
4027
  @uri.query_values = "bogus"
4016
- end).to raise_error(TypeError)
4028
+ end.to raise_error(TypeError)
4017
4029
  end
4018
4030
 
4019
4031
  it "should have the correct fragment after assignment" do
@@ -4085,39 +4097,39 @@ describe Addressable::URI, "when parsed from " +
4085
4097
  end
4086
4098
 
4087
4099
  it "should fail to merge with bogus values" do
4088
- expect(lambda do
4100
+ expect do
4089
4101
  @uri.merge(:port => "bogus")
4090
- end).to raise_error(Addressable::URI::InvalidURIError)
4102
+ end.to raise_error(Addressable::URI::InvalidURIError)
4091
4103
  end
4092
4104
 
4093
4105
  it "should fail to merge with bogus values" do
4094
- expect(lambda do
4106
+ expect do
4095
4107
  @uri.merge(:authority => "bar@baz:bogus")
4096
- end).to raise_error(Addressable::URI::InvalidURIError)
4108
+ end.to raise_error(Addressable::URI::InvalidURIError)
4097
4109
  end
4098
4110
 
4099
4111
  it "should fail to merge with bogus parameters" do
4100
- expect(lambda do
4112
+ expect do
4101
4113
  @uri.merge(42)
4102
- end).to raise_error(TypeError)
4114
+ end.to raise_error(TypeError)
4103
4115
  end
4104
4116
 
4105
4117
  it "should fail to merge with bogus parameters" do
4106
- expect(lambda do
4118
+ expect do
4107
4119
  @uri.merge("http://example.com/")
4108
- end).to raise_error(TypeError)
4120
+ end.to raise_error(TypeError)
4109
4121
  end
4110
4122
 
4111
4123
  it "should fail to merge with both authority and subcomponents" do
4112
- expect(lambda do
4124
+ expect do
4113
4125
  @uri.merge(:authority => "foo:bar@baz:42", :port => "42")
4114
- end).to raise_error(ArgumentError)
4126
+ end.to raise_error(ArgumentError)
4115
4127
  end
4116
4128
 
4117
4129
  it "should fail to merge with both userinfo and subcomponents" do
4118
- expect(lambda do
4130
+ expect do
4119
4131
  @uri.merge(:userinfo => "foo:bar", :user => "foo")
4120
- end).to raise_error(ArgumentError)
4132
+ end.to raise_error(ArgumentError)
4121
4133
  end
4122
4134
 
4123
4135
  it "should be identical to its duplicate" do
@@ -4250,6 +4262,36 @@ describe Addressable::URI, "when parsed from " +
4250
4262
  end
4251
4263
  end
4252
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
+
4253
4295
  describe Addressable::URI, "when parsed from " +
4254
4296
  "'http://example.com/?q=a%2bb'" do
4255
4297
  before do
@@ -4291,6 +4333,46 @@ describe Addressable::URI, "when parsed from " +
4291
4333
  end
4292
4334
  end
4293
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
+
4294
4376
  describe Addressable::URI, "when parsed from " +
4295
4377
  "'http://example.com/sound%2bvision'" do
4296
4378
  before do
@@ -4402,10 +4484,10 @@ describe Addressable::URI, "when parsed from " +
4402
4484
  end
4403
4485
 
4404
4486
  it "should raise an error after nil assignment of authority segment" do
4405
- expect(lambda do
4487
+ expect do
4406
4488
  # This would create an invalid URI
4407
4489
  @uri.authority = nil
4408
- end).to raise_error
4490
+ end.to raise_error(Addressable::URI::InvalidURIError)
4409
4491
  end
4410
4492
  end
4411
4493
 
@@ -4634,12 +4716,12 @@ describe Addressable::URI, "when parsed from " +
4634
4716
  end
4635
4717
 
4636
4718
  it "should raise an error if routing is attempted" do
4637
- expect(lambda do
4719
+ expect do
4638
4720
  @uri.route_to("http://example.com/")
4639
- end).to raise_error(ArgumentError, /\/\/example.com\//)
4640
- expect(lambda do
4721
+ end.to raise_error(ArgumentError, /\/\/example.com\//)
4722
+ expect do
4641
4723
  @uri.route_from("http://example.com/")
4642
- end).to raise_error(ArgumentError, /\/\/example.com\//)
4724
+ end.to raise_error(ArgumentError, /\/\/example.com\//)
4643
4725
  end
4644
4726
 
4645
4727
  it "should have a 'null' origin" do
@@ -4733,9 +4815,9 @@ end
4733
4815
  describe Addressable::URI, "when parsed from " +
4734
4816
  "'http://under_score.example.com/'" do
4735
4817
  it "should not cause an error" do
4736
- expect(lambda do
4818
+ expect do
4737
4819
  Addressable::URI.parse("http://under_score.example.com/")
4738
- end).not_to raise_error
4820
+ end.not_to raise_error
4739
4821
  end
4740
4822
  end
4741
4823
 
@@ -4807,9 +4889,9 @@ describe Addressable::URI, "when parsed from '?one=1&two=2&three=3'" do
4807
4889
  end
4808
4890
 
4809
4891
  it "should raise an error for invalid return type values" do
4810
- expect(lambda do
4811
- @uri.query_values(Fixnum)
4812
- end).to raise_error(ArgumentError)
4892
+ expect do
4893
+ @uri.query_values(Integer)
4894
+ end.to raise_error(ArgumentError)
4813
4895
  end
4814
4896
 
4815
4897
  it "should have the correct array query values" do
@@ -5410,9 +5492,9 @@ describe Addressable::URI, "with a base uri of 'http://a/b/c/d;p?q'" do
5410
5492
  end
5411
5493
 
5412
5494
  it "when joined with a bogus object a TypeError should be raised" do
5413
- expect(lambda do
5495
+ expect do
5414
5496
  Addressable::URI.join(@uri, 42)
5415
- end).to raise_error(TypeError)
5497
+ end.to raise_error(TypeError)
5416
5498
  end
5417
5499
  end
5418
5500
 
@@ -5439,9 +5521,9 @@ end
5439
5521
 
5440
5522
  describe Addressable::URI, "when converting a bogus path" do
5441
5523
  it "should raise a TypeError" do
5442
- expect(lambda do
5524
+ expect do
5443
5525
  Addressable::URI.convert_path(42)
5444
- end).to raise_error(TypeError)
5526
+ end.to raise_error(TypeError)
5445
5527
  end
5446
5528
  end
5447
5529
 
@@ -5494,6 +5576,31 @@ describe Addressable::URI, "when given the path '/one/two/'" do
5494
5576
  end
5495
5577
  end
5496
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
+
5497
5604
  describe Addressable::URI, "when given the path " +
5498
5605
  "'c:\\windows\\My Documents 100%20\\foo.txt'" do
5499
5606
  before do
@@ -5611,9 +5718,9 @@ describe Addressable::URI, "when parsing a non-String object" do
5611
5718
  end
5612
5719
 
5613
5720
  it "should raise a TypeError for objects than cannot be converted" do
5614
- expect(lambda do
5721
+ expect do
5615
5722
  Addressable::URI.parse(42)
5616
- end).to raise_error(TypeError)
5723
+ end.to raise_error(TypeError)
5617
5724
  end
5618
5725
 
5619
5726
  it "should correctly parse heuristically anything with a 'to_str' method" do
@@ -5621,9 +5728,9 @@ describe Addressable::URI, "when parsing a non-String object" do
5621
5728
  end
5622
5729
 
5623
5730
  it "should raise a TypeError for objects than cannot be converted" do
5624
- expect(lambda do
5731
+ expect do
5625
5732
  Addressable::URI.heuristic_parse(42)
5626
- end).to raise_error(TypeError)
5733
+ end.to raise_error(TypeError)
5627
5734
  end
5628
5735
  end
5629
5736
 
@@ -5667,9 +5774,9 @@ end
5667
5774
 
5668
5775
  describe Addressable::URI, "when form encoding a non-Array object" do
5669
5776
  it "should raise a TypeError for objects than cannot be converted" do
5670
- expect(lambda do
5777
+ expect do
5671
5778
  Addressable::URI.form_encode(42)
5672
- end).to raise_error(TypeError)
5779
+ end.to raise_error(TypeError)
5673
5780
  end
5674
5781
  end
5675
5782
 
@@ -5735,9 +5842,9 @@ describe Addressable::URI, "when form unencoding a non-String object" do
5735
5842
  end
5736
5843
 
5737
5844
  it "should raise a TypeError for objects than cannot be converted" do
5738
- expect(lambda do
5845
+ expect do
5739
5846
  Addressable::URI.form_unencode(42)
5740
- end).to raise_error(TypeError)
5847
+ end.to raise_error(TypeError)
5741
5848
  end
5742
5849
  end
5743
5850
 
@@ -5747,15 +5854,15 @@ describe Addressable::URI, "when normalizing a non-String object" do
5747
5854
  end
5748
5855
 
5749
5856
  it "should raise a TypeError for objects than cannot be converted" do
5750
- expect(lambda do
5857
+ expect do
5751
5858
  Addressable::URI.normalize_component(42)
5752
- end).to raise_error(TypeError)
5859
+ end.to raise_error(TypeError)
5753
5860
  end
5754
5861
 
5755
5862
  it "should raise a TypeError for objects than cannot be converted" do
5756
- expect(lambda do
5863
+ expect do
5757
5864
  Addressable::URI.normalize_component("component", 42)
5758
- end).to raise_error(TypeError)
5865
+ end.to raise_error(TypeError)
5759
5866
  end
5760
5867
  end
5761
5868
 
@@ -5827,6 +5934,18 @@ describe Addressable::URI, "when normalizing a string but leaving some character
5827
5934
  end
5828
5935
  end
5829
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
+
5830
5949
  describe Addressable::URI, "when encoding a string with existing encodings to upcase" do
5831
5950
  it "should result in correct percent encoded sequence" do
5832
5951
  expect(Addressable::URI.encode_component("JK%4c", "0-9A-IKM-Za-z%", "L")).to eq("%4AK%4C")
@@ -5899,41 +6018,41 @@ end
5899
6018
 
5900
6019
  describe Addressable::URI, "when unencoding a bogus object" do
5901
6020
  it "should raise a TypeError" do
5902
- expect(lambda do
6021
+ expect do
5903
6022
  Addressable::URI.unencode_component(42)
5904
- end).to raise_error(TypeError)
6023
+ end.to raise_error(TypeError)
5905
6024
  end
5906
6025
 
5907
6026
  it "should raise a TypeError" do
5908
- expect(lambda do
6027
+ expect do
5909
6028
  Addressable::URI.unencode("/path?g%C3%BCnther", Integer)
5910
- end).to raise_error(TypeError)
6029
+ end.to raise_error(TypeError)
5911
6030
  end
5912
6031
  end
5913
6032
 
5914
6033
  describe Addressable::URI, "when encoding a bogus object" do
5915
6034
  it "should raise a TypeError" do
5916
- expect(lambda do
6035
+ expect do
5917
6036
  Addressable::URI.encode(Object.new)
5918
- end).to raise_error(TypeError)
6037
+ end.to raise_error(TypeError)
5919
6038
  end
5920
6039
 
5921
6040
  it "should raise a TypeError" do
5922
- expect(lambda do
6041
+ expect do
5923
6042
  Addressable::URI.normalized_encode(Object.new)
5924
- end).to raise_error(TypeError)
6043
+ end.to raise_error(TypeError)
5925
6044
  end
5926
6045
 
5927
6046
  it "should raise a TypeError" do
5928
- expect(lambda do
6047
+ expect do
5929
6048
  Addressable::URI.encode_component("günther", Object.new)
5930
- end).to raise_error(TypeError)
6049
+ end.to raise_error(TypeError)
5931
6050
  end
5932
6051
 
5933
6052
  it "should raise a TypeError" do
5934
- expect(lambda do
6053
+ expect do
5935
6054
  Addressable::URI.encode_component(Object.new)
5936
- end).to raise_error(TypeError)
6055
+ end.to raise_error(TypeError)
5937
6056
  end
5938
6057
  end
5939
6058
 
@@ -5949,9 +6068,9 @@ describe Addressable::URI, "when given the input " +
5949
6068
  end
5950
6069
 
5951
6070
  it "should not raise error when frozen" do
5952
- expect(lambda do
6071
+ expect do
5953
6072
  Addressable::URI.heuristic_parse(@input).freeze.to_s
5954
- end).not_to raise_error
6073
+ end.not_to raise_error
5955
6074
  end
5956
6075
  end
5957
6076
 
@@ -6231,6 +6350,18 @@ describe Addressable::URI, "when given the input " +
6231
6350
  end
6232
6351
  end
6233
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
+
6234
6365
  describe Addressable::URI, "when given the input " +
6235
6366
  "'feed:///example.com'" do
6236
6367
  before do
@@ -6243,6 +6374,18 @@ describe Addressable::URI, "when given the input " +
6243
6374
  end
6244
6375
  end
6245
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
+
6246
6389
  describe Addressable::URI, "when given the input " +
6247
6390
  "'file://path/to/resource/'" do
6248
6391
  before do
@@ -6255,6 +6398,18 @@ describe Addressable::URI, "when given the input " +
6255
6398
  end
6256
6399
  end
6257
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
+
6258
6413
  describe Addressable::URI, "when given the input " +
6259
6414
  "'feed://http://example.com'" do
6260
6415
  before do
@@ -6279,6 +6434,44 @@ describe Addressable::URI, "when given the input " +
6279
6434
  end
6280
6435
  end
6281
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
+
6282
6475
  describe Addressable::URI, "when assigning query values" do
6283
6476
  before do
6284
6477
  @uri = Addressable::URI.new
@@ -6290,54 +6483,54 @@ describe Addressable::URI, "when assigning query values" do
6290
6483
  end
6291
6484
 
6292
6485
  it "should raise an error attempting to assign {'a' => {'b' => ['c']}}" do
6293
- expect(lambda do
6486
+ expect do
6294
6487
  @uri.query_values = { 'a' => {'b' => ['c'] } }
6295
- end).to raise_error(TypeError)
6488
+ end.to raise_error(TypeError)
6296
6489
  end
6297
6490
 
6298
6491
  it "should raise an error attempting to assign " +
6299
6492
  "{:b => '2', :a => {:c => '1'}}" do
6300
- expect(lambda do
6493
+ expect do
6301
6494
  @uri.query_values = {:b => '2', :a => {:c => '1'}}
6302
- end).to raise_error(TypeError)
6495
+ end.to raise_error(TypeError)
6303
6496
  end
6304
6497
 
6305
6498
  it "should raise an error attempting to assign " +
6306
6499
  "{:a => 'a', :b => [{:c => 'c', :d => 'd'}, " +
6307
6500
  "{:e => 'e', :f => 'f'}]}" do
6308
- expect(lambda do
6501
+ expect do
6309
6502
  @uri.query_values = {
6310
6503
  :a => "a", :b => [{:c => "c", :d => "d"}, {:e => "e", :f => "f"}]
6311
6504
  }
6312
- end).to raise_error(TypeError)
6505
+ end.to raise_error(TypeError)
6313
6506
  end
6314
6507
 
6315
6508
  it "should raise an error attempting to assign " +
6316
6509
  "{:a => 'a', :b => [{:c => true, :d => 'd'}, " +
6317
6510
  "{:e => 'e', :f => 'f'}]}" do
6318
- expect(lambda do
6511
+ expect do
6319
6512
  @uri.query_values = {
6320
6513
  :a => 'a', :b => [{:c => true, :d => 'd'}, {:e => 'e', :f => 'f'}]
6321
6514
  }
6322
- end).to raise_error(TypeError)
6515
+ end.to raise_error(TypeError)
6323
6516
  end
6324
6517
 
6325
6518
  it "should raise an error attempting to assign " +
6326
6519
  "{:a => 'a', :b => {:c => true, :d => 'd'}}" do
6327
- expect(lambda do
6520
+ expect do
6328
6521
  @uri.query_values = {
6329
6522
  :a => 'a', :b => {:c => true, :d => 'd'}
6330
6523
  }
6331
- end).to raise_error(TypeError)
6524
+ end.to raise_error(TypeError)
6332
6525
  end
6333
6526
 
6334
6527
  it "should raise an error attempting to assign " +
6335
6528
  "{:a => 'a', :b => {:c => true, :d => 'd'}}" do
6336
- expect(lambda do
6529
+ expect do
6337
6530
  @uri.query_values = {
6338
6531
  :a => 'a', :b => {:c => true, :d => 'd'}
6339
6532
  }
6340
- end).to raise_error(TypeError)
6533
+ end.to raise_error(TypeError)
6341
6534
  end
6342
6535
 
6343
6536
  it "should correctly assign {:a => 1, :b => 1.5}" do
@@ -6348,13 +6541,13 @@ describe Addressable::URI, "when assigning query values" do
6348
6541
  it "should raise an error attempting to assign " +
6349
6542
  "{:z => 1, :f => [2, {999.1 => [3,'4']}, ['h', 'i']], " +
6350
6543
  ":a => {:b => ['c', 'd'], :e => true, :y => 0.5}}" do
6351
- expect(lambda do
6544
+ expect do
6352
6545
  @uri.query_values = {
6353
6546
  :z => 1,
6354
6547
  :f => [ 2, {999.1 => [3,'4']}, ['h', 'i'] ],
6355
6548
  :a => { :b => ['c', 'd'], :e => true, :y => 0.5 }
6356
6549
  }
6357
- end).to raise_error(TypeError)
6550
+ end.to raise_error(TypeError)
6358
6551
  end
6359
6552
 
6360
6553
  it "should correctly assign {}" do
@@ -6404,7 +6597,7 @@ describe Addressable::URI, "when assigning path values" do
6404
6597
  @uri.path = "acct:bob@sporkmonger.com"
6405
6598
  expect(@uri.path).to eq("acct:bob@sporkmonger.com")
6406
6599
  expect(@uri.normalize.to_str).to eq("acct%2Fbob@sporkmonger.com")
6407
- expect(lambda { @uri.to_s }).to raise_error(
6600
+ expect { @uri.to_s }.to raise_error(
6408
6601
  Addressable::URI::InvalidURIError
6409
6602
  )
6410
6603
  end
@@ -6422,26 +6615,26 @@ describe Addressable::URI, "when assigning path values" do
6422
6615
  end
6423
6616
 
6424
6617
  it "should not allow relative paths to be assigned on absolute URIs" do
6425
- expect(lambda do
6618
+ expect do
6426
6619
  @uri.scheme = "http"
6427
6620
  @uri.host = "example.com"
6428
6621
  @uri.path = "acct:bob@sporkmonger.com"
6429
- end).to raise_error(Addressable::URI::InvalidURIError)
6622
+ end.to raise_error(Addressable::URI::InvalidURIError)
6430
6623
  end
6431
6624
 
6432
6625
  it "should not allow relative paths to be assigned on absolute URIs" do
6433
- expect(lambda do
6626
+ expect do
6434
6627
  @uri.path = "acct:bob@sporkmonger.com"
6435
6628
  @uri.scheme = "http"
6436
6629
  @uri.host = "example.com"
6437
- end).to raise_error(Addressable::URI::InvalidURIError)
6630
+ end.to raise_error(Addressable::URI::InvalidURIError)
6438
6631
  end
6439
6632
 
6440
6633
  it "should not allow relative paths to be assigned on absolute URIs" do
6441
- expect(lambda do
6634
+ expect do
6442
6635
  @uri.path = "uuid:0b3ecf60-3f93-11df-a9c3-001f5bfffe12"
6443
6636
  @uri.scheme = "urn"
6444
- end).not_to raise_error
6637
+ end.not_to raise_error
6445
6638
  end
6446
6639
  end
6447
6640