addressable 2.6.0 → 2.8.5
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.
- checksums.yaml +5 -5
- data/CHANGELOG.md +64 -0
- data/Gemfile +14 -16
- data/README.md +12 -10
- data/Rakefile +14 -8
- data/addressable.gemspec +28 -0
- data/lib/addressable/idna/native.rb +8 -3
- data/lib/addressable/idna/pure.rb +20 -191
- data/lib/addressable/idna.rb +0 -1
- data/lib/addressable/template.rb +37 -53
- data/lib/addressable/uri.rb +257 -176
- data/lib/addressable/version.rb +2 -3
- data/spec/addressable/idna_spec.rb +9 -7
- data/spec/addressable/net_http_compat_spec.rb +0 -1
- data/spec/addressable/security_spec.rb +0 -1
- data/spec/addressable/template_spec.rb +78 -265
- data/spec/addressable/uri_spec.rb +503 -208
- data/spec/spec_helper.rb +9 -0
- data/tasks/gem.rake +9 -7
- data/tasks/profile.rake +72 -0
- data/tasks/rspec.rake +1 -1
- metadata +16 -15
- data/spec/addressable/rack_mount_compat_spec.rb +0 -106
@@ -1,6 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# coding: utf-8
|
4
3
|
# Copyright (C) Bob Aman
|
5
4
|
#
|
6
5
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -21,6 +20,7 @@ require "spec_helper"
|
|
21
20
|
require "addressable/uri"
|
22
21
|
require "uri"
|
23
22
|
require "ipaddr"
|
23
|
+
require "yaml"
|
24
24
|
|
25
25
|
if !"".respond_to?("force_encoding")
|
26
26
|
class String
|
@@ -65,116 +65,116 @@ end
|
|
65
65
|
|
66
66
|
describe Addressable::URI, "when created with a non-numeric port number" do
|
67
67
|
it "should raise an error" do
|
68
|
-
expect
|
68
|
+
expect do
|
69
69
|
Addressable::URI.new(:port => "bogus")
|
70
|
-
end
|
70
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
74
|
describe Addressable::URI, "when created with a invalid encoded port number" do
|
75
75
|
it "should raise an error" do
|
76
|
-
expect
|
76
|
+
expect do
|
77
77
|
Addressable::URI.new(:port => "%eb")
|
78
|
-
end
|
78
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
82
|
describe Addressable::URI, "when created with a non-string scheme" do
|
83
83
|
it "should raise an error" do
|
84
|
-
expect
|
84
|
+
expect do
|
85
85
|
Addressable::URI.new(:scheme => :bogus)
|
86
|
-
end
|
86
|
+
end.to raise_error(TypeError)
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
90
|
describe Addressable::URI, "when created with a non-string user" do
|
91
91
|
it "should raise an error" do
|
92
|
-
expect
|
92
|
+
expect do
|
93
93
|
Addressable::URI.new(:user => :bogus)
|
94
|
-
end
|
94
|
+
end.to raise_error(TypeError)
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
98
|
describe Addressable::URI, "when created with a non-string password" do
|
99
99
|
it "should raise an error" do
|
100
|
-
expect
|
100
|
+
expect do
|
101
101
|
Addressable::URI.new(:password => :bogus)
|
102
|
-
end
|
102
|
+
end.to raise_error(TypeError)
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
106
106
|
describe Addressable::URI, "when created with a non-string userinfo" do
|
107
107
|
it "should raise an error" do
|
108
|
-
expect
|
108
|
+
expect do
|
109
109
|
Addressable::URI.new(:userinfo => :bogus)
|
110
|
-
end
|
110
|
+
end.to raise_error(TypeError)
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
114
114
|
describe Addressable::URI, "when created with a non-string host" do
|
115
115
|
it "should raise an error" do
|
116
|
-
expect
|
116
|
+
expect do
|
117
117
|
Addressable::URI.new(:host => :bogus)
|
118
|
-
end
|
118
|
+
end.to raise_error(TypeError)
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
122
122
|
describe Addressable::URI, "when created with a non-string authority" do
|
123
123
|
it "should raise an error" do
|
124
|
-
expect
|
124
|
+
expect do
|
125
125
|
Addressable::URI.new(:authority => :bogus)
|
126
|
-
end
|
126
|
+
end.to raise_error(TypeError)
|
127
127
|
end
|
128
128
|
end
|
129
129
|
|
130
130
|
describe Addressable::URI, "when created with a non-string path" do
|
131
131
|
it "should raise an error" do
|
132
|
-
expect
|
132
|
+
expect do
|
133
133
|
Addressable::URI.new(:path => :bogus)
|
134
|
-
end
|
134
|
+
end.to raise_error(TypeError)
|
135
135
|
end
|
136
136
|
end
|
137
137
|
|
138
138
|
describe Addressable::URI, "when created with a non-string query" do
|
139
139
|
it "should raise an error" do
|
140
|
-
expect
|
140
|
+
expect do
|
141
141
|
Addressable::URI.new(:query => :bogus)
|
142
|
-
end
|
142
|
+
end.to raise_error(TypeError)
|
143
143
|
end
|
144
144
|
end
|
145
145
|
|
146
146
|
describe Addressable::URI, "when created with a non-string fragment" do
|
147
147
|
it "should raise an error" do
|
148
|
-
expect
|
148
|
+
expect do
|
149
149
|
Addressable::URI.new(:fragment => :bogus)
|
150
|
-
end
|
150
|
+
end.to raise_error(TypeError)
|
151
151
|
end
|
152
152
|
end
|
153
153
|
|
154
154
|
describe Addressable::URI, "when created with a scheme but no hierarchical " +
|
155
155
|
"segment" do
|
156
156
|
it "should raise an error" do
|
157
|
-
expect
|
157
|
+
expect do
|
158
158
|
Addressable::URI.parse("http:")
|
159
|
-
end
|
159
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
160
160
|
end
|
161
161
|
end
|
162
162
|
|
163
163
|
describe Addressable::URI, "quote handling" do
|
164
164
|
describe 'in host name' do
|
165
165
|
it "should raise an error for single quote" do
|
166
|
-
expect
|
166
|
+
expect do
|
167
167
|
Addressable::URI.parse("http://local\"host/")
|
168
|
-
end
|
168
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
169
169
|
end
|
170
170
|
end
|
171
171
|
end
|
172
172
|
|
173
173
|
describe Addressable::URI, "newline normalization" do
|
174
174
|
it "should not accept newlines in scheme" do
|
175
|
-
expect
|
175
|
+
expect do
|
176
176
|
Addressable::URI.parse("ht%0atp://localhost/")
|
177
|
-
end
|
177
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
178
178
|
end
|
179
179
|
|
180
180
|
it "should not unescape newline in path" do
|
@@ -199,47 +199,47 @@ describe Addressable::URI, "newline normalization" do
|
|
199
199
|
|
200
200
|
it "should not accept newline in hostname" do
|
201
201
|
uri = Addressable::URI.parse("http://localhost/")
|
202
|
-
expect
|
202
|
+
expect do
|
203
203
|
uri.host = "local\nhost"
|
204
|
-
end
|
204
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
205
205
|
end
|
206
206
|
end
|
207
207
|
|
208
208
|
describe Addressable::URI, "when created with ambiguous path" do
|
209
209
|
it "should raise an error" do
|
210
|
-
expect
|
210
|
+
expect do
|
211
211
|
Addressable::URI.parse("::http")
|
212
|
-
end
|
212
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
213
213
|
end
|
214
214
|
end
|
215
215
|
|
216
216
|
describe Addressable::URI, "when created with an invalid host" do
|
217
217
|
it "should raise an error" do
|
218
|
-
expect
|
218
|
+
expect do
|
219
219
|
Addressable::URI.new(:host => "<invalid>")
|
220
|
-
end
|
220
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
221
221
|
end
|
222
222
|
end
|
223
223
|
|
224
224
|
describe Addressable::URI, "when created with a host consisting of " +
|
225
225
|
"sub-delims characters" do
|
226
226
|
it "should not raise an error" do
|
227
|
-
expect
|
227
|
+
expect do
|
228
228
|
Addressable::URI.new(
|
229
229
|
:host => Addressable::URI::CharacterClasses::SUB_DELIMS.gsub(/\\/, '')
|
230
230
|
)
|
231
|
-
end
|
231
|
+
end.not_to raise_error
|
232
232
|
end
|
233
233
|
end
|
234
234
|
|
235
235
|
describe Addressable::URI, "when created with a host consisting of " +
|
236
236
|
"unreserved characters" do
|
237
237
|
it "should not raise an error" do
|
238
|
-
expect
|
238
|
+
expect do
|
239
239
|
Addressable::URI.new(
|
240
240
|
:host => Addressable::URI::CharacterClasses::UNRESERVED.gsub(/\\/, '')
|
241
241
|
)
|
242
|
-
end
|
242
|
+
end.not_to raise_error
|
243
243
|
end
|
244
244
|
end
|
245
245
|
|
@@ -269,83 +269,83 @@ describe Addressable::URI, "when created from nil components" do
|
|
269
269
|
end
|
270
270
|
|
271
271
|
it "should raise an error if the scheme is set to whitespace" do
|
272
|
-
expect
|
272
|
+
expect do
|
273
273
|
@uri.scheme = "\t \n"
|
274
|
-
end
|
274
|
+
end.to raise_error(Addressable::URI::InvalidURIError, /'\t \n'/)
|
275
275
|
end
|
276
276
|
|
277
277
|
it "should raise an error if the scheme is set to all digits" do
|
278
|
-
expect
|
278
|
+
expect do
|
279
279
|
@uri.scheme = "123"
|
280
|
-
end
|
280
|
+
end.to raise_error(Addressable::URI::InvalidURIError, /'123'/)
|
281
281
|
end
|
282
282
|
|
283
283
|
it "should raise an error if the scheme begins with a digit" do
|
284
|
-
expect
|
284
|
+
expect do
|
285
285
|
@uri.scheme = "1scheme"
|
286
|
-
end
|
286
|
+
end.to raise_error(Addressable::URI::InvalidURIError, /'1scheme'/)
|
287
287
|
end
|
288
288
|
|
289
289
|
it "should raise an error if the scheme begins with a plus" do
|
290
|
-
expect
|
290
|
+
expect do
|
291
291
|
@uri.scheme = "+scheme"
|
292
|
-
end
|
292
|
+
end.to raise_error(Addressable::URI::InvalidURIError, /'\+scheme'/)
|
293
293
|
end
|
294
294
|
|
295
295
|
it "should raise an error if the scheme begins with a dot" do
|
296
|
-
expect
|
296
|
+
expect do
|
297
297
|
@uri.scheme = ".scheme"
|
298
|
-
end
|
298
|
+
end.to raise_error(Addressable::URI::InvalidURIError, /'\.scheme'/)
|
299
299
|
end
|
300
300
|
|
301
301
|
it "should raise an error if the scheme begins with a dash" do
|
302
|
-
expect
|
302
|
+
expect do
|
303
303
|
@uri.scheme = "-scheme"
|
304
|
-
end
|
304
|
+
end.to raise_error(Addressable::URI::InvalidURIError, /'-scheme'/)
|
305
305
|
end
|
306
306
|
|
307
307
|
it "should raise an error if the scheme contains an illegal character" do
|
308
|
-
expect
|
308
|
+
expect do
|
309
309
|
@uri.scheme = "scheme!"
|
310
|
-
end
|
310
|
+
end.to raise_error(Addressable::URI::InvalidURIError, /'scheme!'/)
|
311
311
|
end
|
312
312
|
|
313
313
|
it "should raise an error if the scheme contains whitespace" do
|
314
|
-
expect
|
314
|
+
expect do
|
315
315
|
@uri.scheme = "sch eme"
|
316
|
-
end
|
316
|
+
end.to raise_error(Addressable::URI::InvalidURIError, /'sch eme'/)
|
317
317
|
end
|
318
318
|
|
319
319
|
it "should raise an error if the scheme contains a newline" do
|
320
|
-
expect
|
320
|
+
expect do
|
321
321
|
@uri.scheme = "sch\neme"
|
322
|
-
end
|
322
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
323
323
|
end
|
324
324
|
|
325
325
|
it "should raise an error if set into an invalid state" do
|
326
|
-
expect
|
326
|
+
expect do
|
327
327
|
@uri.user = "user"
|
328
|
-
end
|
328
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
329
329
|
end
|
330
330
|
|
331
331
|
it "should raise an error if set into an invalid state" do
|
332
|
-
expect
|
332
|
+
expect do
|
333
333
|
@uri.password = "pass"
|
334
|
-
end
|
334
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
335
335
|
end
|
336
336
|
|
337
337
|
it "should raise an error if set into an invalid state" do
|
338
|
-
expect
|
338
|
+
expect do
|
339
339
|
@uri.scheme = "http"
|
340
340
|
@uri.fragment = "fragment"
|
341
|
-
end
|
341
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
342
342
|
end
|
343
343
|
|
344
344
|
it "should raise an error if set into an invalid state" do
|
345
|
-
expect
|
345
|
+
expect do
|
346
346
|
@uri.fragment = "fragment"
|
347
347
|
@uri.scheme = "http"
|
348
|
-
end
|
348
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
349
349
|
end
|
350
350
|
end
|
351
351
|
|
@@ -999,6 +999,72 @@ describe Addressable::URI, "when frozen" do
|
|
999
999
|
end
|
1000
1000
|
end
|
1001
1001
|
|
1002
|
+
describe Addressable::URI, "when normalized and then deeply frozen" do
|
1003
|
+
before do
|
1004
|
+
@uri = Addressable::URI.parse(
|
1005
|
+
"http://user:password@example.com:8080/path?query=value#fragment"
|
1006
|
+
).normalize!
|
1007
|
+
|
1008
|
+
@uri.instance_variables.each do |var|
|
1009
|
+
@uri.instance_variable_set(var, @uri.instance_variable_get(var).freeze)
|
1010
|
+
end
|
1011
|
+
|
1012
|
+
@uri.freeze
|
1013
|
+
end
|
1014
|
+
|
1015
|
+
it "#normalized_scheme should not error" do
|
1016
|
+
expect { @uri.normalized_scheme }.not_to raise_error
|
1017
|
+
end
|
1018
|
+
|
1019
|
+
it "#normalized_user should not error" do
|
1020
|
+
expect { @uri.normalized_user }.not_to raise_error
|
1021
|
+
end
|
1022
|
+
|
1023
|
+
it "#normalized_password should not error" do
|
1024
|
+
expect { @uri.normalized_password }.not_to raise_error
|
1025
|
+
end
|
1026
|
+
|
1027
|
+
it "#normalized_userinfo should not error" do
|
1028
|
+
expect { @uri.normalized_userinfo }.not_to raise_error
|
1029
|
+
end
|
1030
|
+
|
1031
|
+
it "#normalized_host should not error" do
|
1032
|
+
expect { @uri.normalized_host }.not_to raise_error
|
1033
|
+
end
|
1034
|
+
|
1035
|
+
it "#normalized_authority should not error" do
|
1036
|
+
expect { @uri.normalized_authority }.not_to raise_error
|
1037
|
+
end
|
1038
|
+
|
1039
|
+
it "#normalized_port should not error" do
|
1040
|
+
expect { @uri.normalized_port }.not_to raise_error
|
1041
|
+
end
|
1042
|
+
|
1043
|
+
it "#normalized_site should not error" do
|
1044
|
+
expect { @uri.normalized_site }.not_to raise_error
|
1045
|
+
end
|
1046
|
+
|
1047
|
+
it "#normalized_path should not error" do
|
1048
|
+
expect { @uri.normalized_path }.not_to raise_error
|
1049
|
+
end
|
1050
|
+
|
1051
|
+
it "#normalized_query should not error" do
|
1052
|
+
expect { @uri.normalized_query }.not_to raise_error
|
1053
|
+
end
|
1054
|
+
|
1055
|
+
it "#normalized_fragment should not error" do
|
1056
|
+
expect { @uri.normalized_fragment }.not_to raise_error
|
1057
|
+
end
|
1058
|
+
|
1059
|
+
it "should be frozen" do
|
1060
|
+
expect(@uri).to be_frozen
|
1061
|
+
end
|
1062
|
+
|
1063
|
+
it "should not allow destructive operations" do
|
1064
|
+
expect { @uri.normalize! }.to raise_error(RuntimeError)
|
1065
|
+
end
|
1066
|
+
end
|
1067
|
+
|
1002
1068
|
describe Addressable::URI, "when created from string components" do
|
1003
1069
|
before do
|
1004
1070
|
@uri = Addressable::URI.new(
|
@@ -1015,31 +1081,31 @@ describe Addressable::URI, "when created from string components" do
|
|
1015
1081
|
end
|
1016
1082
|
|
1017
1083
|
it "should raise an error if invalid components omitted" do
|
1018
|
-
expect
|
1084
|
+
expect do
|
1019
1085
|
@uri.omit(:bogus)
|
1020
|
-
end
|
1021
|
-
expect
|
1086
|
+
end.to raise_error(ArgumentError)
|
1087
|
+
expect do
|
1022
1088
|
@uri.omit(:scheme, :bogus, :path)
|
1023
|
-
end
|
1089
|
+
end.to raise_error(ArgumentError)
|
1024
1090
|
end
|
1025
1091
|
end
|
1026
1092
|
|
1027
1093
|
describe Addressable::URI, "when created with a nil host but " +
|
1028
1094
|
"non-nil authority components" do
|
1029
1095
|
it "should raise an error" do
|
1030
|
-
expect
|
1096
|
+
expect do
|
1031
1097
|
Addressable::URI.new(:user => "user", :password => "pass", :port => 80)
|
1032
|
-
end
|
1098
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
1033
1099
|
end
|
1034
1100
|
end
|
1035
1101
|
|
1036
1102
|
describe Addressable::URI, "when created with both an authority and a user" do
|
1037
1103
|
it "should raise an error" do
|
1038
|
-
expect
|
1104
|
+
expect do
|
1039
1105
|
Addressable::URI.new(
|
1040
1106
|
:user => "user", :authority => "user@example.com:80"
|
1041
1107
|
)
|
1042
|
-
end
|
1108
|
+
end.to raise_error(ArgumentError)
|
1043
1109
|
end
|
1044
1110
|
end
|
1045
1111
|
|
@@ -1077,33 +1143,33 @@ end
|
|
1077
1143
|
|
1078
1144
|
describe Addressable::URI, "when created with a host with a backslash" do
|
1079
1145
|
it "should raise an error" do
|
1080
|
-
expect
|
1146
|
+
expect do
|
1081
1147
|
Addressable::URI.new(:authority => "example\\example")
|
1082
|
-
end
|
1148
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
1083
1149
|
end
|
1084
1150
|
end
|
1085
1151
|
|
1086
1152
|
describe Addressable::URI, "when created with a host with a slash" do
|
1087
1153
|
it "should raise an error" do
|
1088
|
-
expect
|
1154
|
+
expect do
|
1089
1155
|
Addressable::URI.new(:authority => "example/example")
|
1090
|
-
end
|
1156
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
1091
1157
|
end
|
1092
1158
|
end
|
1093
1159
|
|
1094
1160
|
describe Addressable::URI, "when created with a host with a space" do
|
1095
1161
|
it "should raise an error" do
|
1096
|
-
expect
|
1162
|
+
expect do
|
1097
1163
|
Addressable::URI.new(:authority => "example example")
|
1098
|
-
end
|
1164
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
1099
1165
|
end
|
1100
1166
|
end
|
1101
1167
|
|
1102
1168
|
describe Addressable::URI, "when created with both a userinfo and a user" do
|
1103
1169
|
it "should raise an error" do
|
1104
|
-
expect
|
1170
|
+
expect do
|
1105
1171
|
Addressable::URI.new(:user => "user", :userinfo => "user:pass")
|
1106
|
-
end
|
1172
|
+
end.to raise_error(ArgumentError)
|
1107
1173
|
end
|
1108
1174
|
end
|
1109
1175
|
|
@@ -1195,18 +1261,18 @@ describe Addressable::URI, "when parsed from something that looks " +
|
|
1195
1261
|
"like a URI object" do
|
1196
1262
|
it "should parse without error" do
|
1197
1263
|
uri = Addressable::URI.parse(Fake::URI::HTTP.new("http://example.com/"))
|
1198
|
-
expect
|
1264
|
+
expect do
|
1199
1265
|
Addressable::URI.parse(uri)
|
1200
|
-
end
|
1266
|
+
end.not_to raise_error
|
1201
1267
|
end
|
1202
1268
|
end
|
1203
1269
|
|
1204
1270
|
describe Addressable::URI, "when parsed from a standard library URI object" do
|
1205
1271
|
it "should parse without error" do
|
1206
1272
|
uri = Addressable::URI.parse(URI.parse("http://example.com/"))
|
1207
|
-
expect
|
1273
|
+
expect do
|
1208
1274
|
Addressable::URI.parse(uri)
|
1209
|
-
end
|
1275
|
+
end.not_to raise_error
|
1210
1276
|
end
|
1211
1277
|
end
|
1212
1278
|
|
@@ -1366,9 +1432,9 @@ describe Addressable::URI, "when parsed from " +
|
|
1366
1432
|
end
|
1367
1433
|
|
1368
1434
|
it "should not allow request URI assignment" do
|
1369
|
-
expect
|
1435
|
+
expect do
|
1370
1436
|
@uri.request_uri = "/"
|
1371
|
-
end
|
1437
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
1372
1438
|
end
|
1373
1439
|
|
1374
1440
|
it "should have a query of 'objectClass?one'" do
|
@@ -1390,9 +1456,9 @@ describe Addressable::URI, "when parsed from " +
|
|
1390
1456
|
end
|
1391
1457
|
|
1392
1458
|
it "should raise an error if omission would create an invalid URI" do
|
1393
|
-
expect
|
1459
|
+
expect do
|
1394
1460
|
@uri.omit(:authority, :path)
|
1395
|
-
end
|
1461
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
1396
1462
|
end
|
1397
1463
|
|
1398
1464
|
it "should have an origin of 'ldap://[2001:db8::7]'" do
|
@@ -1778,9 +1844,9 @@ describe Addressable::URI, "when parsed from " +
|
|
1778
1844
|
|
1779
1845
|
it "should not be roughly equal to the string " +
|
1780
1846
|
"'http://example.com:bogus/'" do
|
1781
|
-
expect
|
1847
|
+
expect do
|
1782
1848
|
expect(@uri === "http://example.com:bogus/").to eq(false)
|
1783
|
-
end
|
1849
|
+
end.not_to raise_error
|
1784
1850
|
end
|
1785
1851
|
|
1786
1852
|
it "should result in itself when joined with itself" do
|
@@ -1810,21 +1876,21 @@ describe Addressable::URI, "when parsed from " +
|
|
1810
1876
|
end
|
1811
1877
|
|
1812
1878
|
it "should not allow origin assignment without scheme" do
|
1813
|
-
expect
|
1879
|
+
expect do
|
1814
1880
|
@uri.origin = "example.com"
|
1815
|
-
end
|
1881
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
1816
1882
|
end
|
1817
1883
|
|
1818
1884
|
it "should not allow origin assignment without host" do
|
1819
|
-
expect
|
1885
|
+
expect do
|
1820
1886
|
@uri.origin = "http://"
|
1821
|
-
end
|
1887
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
1822
1888
|
end
|
1823
1889
|
|
1824
1890
|
it "should not allow origin assignment with bogus type" do
|
1825
|
-
expect
|
1891
|
+
expect do
|
1826
1892
|
@uri.origin = :bogus
|
1827
|
-
end
|
1893
|
+
end.to raise_error(TypeError)
|
1828
1894
|
end
|
1829
1895
|
|
1830
1896
|
# Section 6.2.3 of RFC 3986
|
@@ -1880,9 +1946,9 @@ describe Addressable::URI, "when parsed from " +
|
|
1880
1946
|
end
|
1881
1947
|
|
1882
1948
|
it "when joined with a bogus object a TypeError should be raised" do
|
1883
|
-
expect
|
1949
|
+
expect do
|
1884
1950
|
@uri.join(42)
|
1885
|
-
end
|
1951
|
+
end.to raise_error(TypeError)
|
1886
1952
|
end
|
1887
1953
|
|
1888
1954
|
it "should have the correct username after assignment" do
|
@@ -2015,15 +2081,15 @@ describe Addressable::URI, "when parsed from " +
|
|
2015
2081
|
end
|
2016
2082
|
|
2017
2083
|
it "should raise an error if the site value is set to something bogus" do
|
2018
|
-
expect
|
2084
|
+
expect do
|
2019
2085
|
@uri.site = 42
|
2020
|
-
end
|
2086
|
+
end.to raise_error(TypeError)
|
2021
2087
|
end
|
2022
2088
|
|
2023
2089
|
it "should raise an error if the request URI is set to something bogus" do
|
2024
|
-
expect
|
2090
|
+
expect do
|
2025
2091
|
@uri.request_uri = 42
|
2026
|
-
end
|
2092
|
+
end.to raise_error(TypeError)
|
2027
2093
|
end
|
2028
2094
|
|
2029
2095
|
it "should correctly convert to a hash" do
|
@@ -2072,9 +2138,9 @@ describe Addressable::URI, "when parsing IPv6 addresses" do
|
|
2072
2138
|
|
2073
2139
|
it "should raise an error for " +
|
2074
2140
|
"'http://[<invalid>]/'" do
|
2075
|
-
expect
|
2141
|
+
expect do
|
2076
2142
|
Addressable::URI.parse("http://[<invalid>]/")
|
2077
|
-
end
|
2143
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
2078
2144
|
end
|
2079
2145
|
end
|
2080
2146
|
|
@@ -2100,9 +2166,9 @@ describe Addressable::URI, "when assigning IPv6 address" do
|
|
2100
2166
|
it "should not allow to set bare IPv6 address as host" do
|
2101
2167
|
uri = Addressable::URI.parse("http://[::1]/")
|
2102
2168
|
skip "not checked"
|
2103
|
-
expect
|
2169
|
+
expect do
|
2104
2170
|
uri.host = '3ffe:1900:4545:3:200:f8ff:fe21:67cf'
|
2105
|
-
end
|
2171
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
2106
2172
|
end
|
2107
2173
|
end
|
2108
2174
|
|
@@ -2134,9 +2200,9 @@ describe Addressable::URI, "when parsing IPvFuture addresses" do
|
|
2134
2200
|
|
2135
2201
|
it "should raise an error for " +
|
2136
2202
|
"'http://[v0.<invalid>]/'" do
|
2137
|
-
expect
|
2203
|
+
expect do
|
2138
2204
|
Addressable::URI.parse("http://[v0.<invalid>]/")
|
2139
|
-
end
|
2205
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
2140
2206
|
end
|
2141
2207
|
end
|
2142
2208
|
|
@@ -2480,9 +2546,9 @@ describe Addressable::URI, "when parsed from " +
|
|
2480
2546
|
end
|
2481
2547
|
|
2482
2548
|
it "should not raise an exception when normalized" do
|
2483
|
-
expect
|
2549
|
+
expect do
|
2484
2550
|
@uri.normalize
|
2485
|
-
end
|
2551
|
+
end.not_to raise_error
|
2486
2552
|
end
|
2487
2553
|
|
2488
2554
|
it "should be considered to be in normal form" do
|
@@ -2534,9 +2600,9 @@ describe Addressable::URI, "when parsed from " +
|
|
2534
2600
|
end
|
2535
2601
|
|
2536
2602
|
it "should not raise an exception when normalized" do
|
2537
|
-
expect
|
2603
|
+
expect do
|
2538
2604
|
@uri.normalize
|
2539
|
-
end
|
2605
|
+
end.not_to raise_error
|
2540
2606
|
end
|
2541
2607
|
|
2542
2608
|
it "should be considered to be in normal form" do
|
@@ -2559,9 +2625,9 @@ describe Addressable::URI, "when parsed from " +
|
|
2559
2625
|
end
|
2560
2626
|
|
2561
2627
|
it "should not raise an exception when normalized" do
|
2562
|
-
expect
|
2628
|
+
expect do
|
2563
2629
|
@uri.normalize
|
2564
|
-
end
|
2630
|
+
end.not_to raise_error
|
2565
2631
|
end
|
2566
2632
|
|
2567
2633
|
it "should be considered to be in normal form" do
|
@@ -2597,9 +2663,9 @@ describe Addressable::URI, "when parsed from " +
|
|
2597
2663
|
end
|
2598
2664
|
|
2599
2665
|
it "should raise an error if encoding with an unexpected return type" do
|
2600
|
-
expect
|
2666
|
+
expect do
|
2601
2667
|
Addressable::URI.normalized_encode(@uri, Integer)
|
2602
|
-
end
|
2668
|
+
end.to raise_error(TypeError)
|
2603
2669
|
end
|
2604
2670
|
|
2605
2671
|
it "if percent encoded should be 'http://example.com/C%25CC%25A7'" do
|
@@ -2615,9 +2681,9 @@ describe Addressable::URI, "when parsed from " +
|
|
2615
2681
|
end
|
2616
2682
|
|
2617
2683
|
it "should raise an error if encoding with an unexpected return type" do
|
2618
|
-
expect
|
2684
|
+
expect do
|
2619
2685
|
Addressable::URI.encode(@uri, Integer)
|
2620
|
-
end
|
2686
|
+
end.to raise_error(TypeError)
|
2621
2687
|
end
|
2622
2688
|
|
2623
2689
|
it "should be identical to its duplicate" do
|
@@ -2752,9 +2818,9 @@ describe Addressable::URI, "when parsed from " +
|
|
2752
2818
|
|
2753
2819
|
it "should not be roughly equal to the string " +
|
2754
2820
|
"'http://example.com:bogus/'" do
|
2755
|
-
expect
|
2821
|
+
expect do
|
2756
2822
|
expect(@uri === "http://example.com:bogus/").to eq(false)
|
2757
|
-
end
|
2823
|
+
end.not_to raise_error
|
2758
2824
|
end
|
2759
2825
|
|
2760
2826
|
it "should result in itself when joined with itself" do
|
@@ -2956,6 +3022,20 @@ describe Addressable::URI, "when parsed from " +
|
|
2956
3022
|
end
|
2957
3023
|
end
|
2958
3024
|
|
3025
|
+
describe Addressable::URI, "when parsed with empty port" do
|
3026
|
+
subject(:uri) do
|
3027
|
+
Addressable::URI.parse("//example.com:")
|
3028
|
+
end
|
3029
|
+
|
3030
|
+
it "should not infer a port" do
|
3031
|
+
expect(uri.port).to be(nil)
|
3032
|
+
end
|
3033
|
+
|
3034
|
+
it "should have a site value of '//example.com'" do
|
3035
|
+
expect(uri.site).to eq("//example.com")
|
3036
|
+
end
|
3037
|
+
end
|
3038
|
+
|
2959
3039
|
describe Addressable::URI, "when parsed from " +
|
2960
3040
|
"'http://example.com/%2E/'" do
|
2961
3041
|
before do
|
@@ -3100,9 +3180,9 @@ describe Addressable::URI, "when parsed from " +
|
|
3100
3180
|
end
|
3101
3181
|
|
3102
3182
|
it "should become invalid when normalized" do
|
3103
|
-
expect
|
3183
|
+
expect do
|
3104
3184
|
@uri.normalize
|
3105
|
-
end
|
3185
|
+
end.to raise_error(Addressable::URI::InvalidURIError, /authority/)
|
3106
3186
|
end
|
3107
3187
|
|
3108
3188
|
it "should have a path of '/..//example.com'" do
|
@@ -3340,12 +3420,12 @@ describe Addressable::URI, "when parsed from " +
|
|
3340
3420
|
end
|
3341
3421
|
|
3342
3422
|
it "should raise an error if routing is attempted" do
|
3343
|
-
expect
|
3423
|
+
expect do
|
3344
3424
|
@uri.route_to("http://example.com/")
|
3345
|
-
end
|
3346
|
-
expect
|
3425
|
+
end.to raise_error(ArgumentError, /relative\/path\/to\/resource/)
|
3426
|
+
expect do
|
3347
3427
|
@uri.route_from("http://example.com/")
|
3348
|
-
end
|
3428
|
+
end.to raise_error(ArgumentError, /relative\/path\/to\/resource/)
|
3349
3429
|
end
|
3350
3430
|
|
3351
3431
|
it "when joined with 'another/relative/path' should be " +
|
@@ -3942,9 +4022,9 @@ describe Addressable::URI, "when parsed from " +
|
|
3942
4022
|
end
|
3943
4023
|
|
3944
4024
|
it "should raise an error if assigning a bogus object to the hostname" do
|
3945
|
-
expect
|
4025
|
+
expect do
|
3946
4026
|
@uri.hostname = Object.new
|
3947
|
-
end
|
4027
|
+
end.to raise_error(TypeError)
|
3948
4028
|
end
|
3949
4029
|
|
3950
4030
|
it "should have the correct port after assignment" do
|
@@ -4023,9 +4103,9 @@ describe Addressable::URI, "when parsed from " +
|
|
4023
4103
|
end
|
4024
4104
|
|
4025
4105
|
it "should raise an error if query values are set to a bogus type" do
|
4026
|
-
expect
|
4106
|
+
expect do
|
4027
4107
|
@uri.query_values = "bogus"
|
4028
|
-
end
|
4108
|
+
end.to raise_error(TypeError)
|
4029
4109
|
end
|
4030
4110
|
|
4031
4111
|
it "should have the correct fragment after assignment" do
|
@@ -4097,39 +4177,39 @@ describe Addressable::URI, "when parsed from " +
|
|
4097
4177
|
end
|
4098
4178
|
|
4099
4179
|
it "should fail to merge with bogus values" do
|
4100
|
-
expect
|
4180
|
+
expect do
|
4101
4181
|
@uri.merge(:port => "bogus")
|
4102
|
-
end
|
4182
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
4103
4183
|
end
|
4104
4184
|
|
4105
4185
|
it "should fail to merge with bogus values" do
|
4106
|
-
expect
|
4186
|
+
expect do
|
4107
4187
|
@uri.merge(:authority => "bar@baz:bogus")
|
4108
|
-
end
|
4188
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
4109
4189
|
end
|
4110
4190
|
|
4111
4191
|
it "should fail to merge with bogus parameters" do
|
4112
|
-
expect
|
4192
|
+
expect do
|
4113
4193
|
@uri.merge(42)
|
4114
|
-
end
|
4194
|
+
end.to raise_error(TypeError)
|
4115
4195
|
end
|
4116
4196
|
|
4117
4197
|
it "should fail to merge with bogus parameters" do
|
4118
|
-
expect
|
4198
|
+
expect do
|
4119
4199
|
@uri.merge("http://example.com/")
|
4120
|
-
end
|
4200
|
+
end.to raise_error(TypeError)
|
4121
4201
|
end
|
4122
4202
|
|
4123
4203
|
it "should fail to merge with both authority and subcomponents" do
|
4124
|
-
expect
|
4204
|
+
expect do
|
4125
4205
|
@uri.merge(:authority => "foo:bar@baz:42", :port => "42")
|
4126
|
-
end
|
4206
|
+
end.to raise_error(ArgumentError)
|
4127
4207
|
end
|
4128
4208
|
|
4129
4209
|
it "should fail to merge with both userinfo and subcomponents" do
|
4130
|
-
expect
|
4210
|
+
expect do
|
4131
4211
|
@uri.merge(:userinfo => "foo:bar", :user => "foo")
|
4132
|
-
end
|
4212
|
+
end.to raise_error(ArgumentError)
|
4133
4213
|
end
|
4134
4214
|
|
4135
4215
|
it "should be identical to its duplicate" do
|
@@ -4262,6 +4342,36 @@ describe Addressable::URI, "when parsed from " +
|
|
4262
4342
|
end
|
4263
4343
|
end
|
4264
4344
|
|
4345
|
+
describe Addressable::URI, "when parsed from 'https://example.com/?q=a+b'" do
|
4346
|
+
before do
|
4347
|
+
@uri = Addressable::URI.parse("https://example.com/?q=a+b")
|
4348
|
+
end
|
4349
|
+
|
4350
|
+
it "should have query_values of {'q' => 'a b'}" do
|
4351
|
+
expect(@uri.query_values).to eq("q" => "a b")
|
4352
|
+
end
|
4353
|
+
end
|
4354
|
+
|
4355
|
+
describe Addressable::URI, "when parsed from 'example.com?q=a+b'" do
|
4356
|
+
before do
|
4357
|
+
@uri = Addressable::URI.parse("example.com?q=a+b")
|
4358
|
+
end
|
4359
|
+
|
4360
|
+
it "should have query_values of {'q' => 'a b'}" do
|
4361
|
+
expect(@uri.query_values).to eq("q" => "a b")
|
4362
|
+
end
|
4363
|
+
end
|
4364
|
+
|
4365
|
+
describe Addressable::URI, "when parsed from 'mailto:?q=a+b'" do
|
4366
|
+
before do
|
4367
|
+
@uri = Addressable::URI.parse("mailto:?q=a+b")
|
4368
|
+
end
|
4369
|
+
|
4370
|
+
it "should have query_values of {'q' => 'a+b'}" do
|
4371
|
+
expect(@uri.query_values).to eq("q" => "a+b")
|
4372
|
+
end
|
4373
|
+
end
|
4374
|
+
|
4265
4375
|
describe Addressable::URI, "when parsed from " +
|
4266
4376
|
"'http://example.com/?q=a%2bb'" do
|
4267
4377
|
before do
|
@@ -4303,6 +4413,46 @@ describe Addressable::URI, "when parsed from " +
|
|
4303
4413
|
end
|
4304
4414
|
end
|
4305
4415
|
|
4416
|
+
describe Addressable::URI, "when parsed from 'http://example/?b=1&a=2&c=3'" do
|
4417
|
+
before do
|
4418
|
+
@uri = Addressable::URI.parse("http://example/?b=1&a=2&c=3")
|
4419
|
+
end
|
4420
|
+
|
4421
|
+
it "should have a sorted normalized query of 'a=2&b=1&c=3'" do
|
4422
|
+
expect(@uri.normalized_query(:sorted)).to eq("a=2&b=1&c=3")
|
4423
|
+
end
|
4424
|
+
end
|
4425
|
+
|
4426
|
+
describe Addressable::URI, "when parsed from 'http://example/?&a&&c&'" do
|
4427
|
+
before do
|
4428
|
+
@uri = Addressable::URI.parse("http://example/?&a&&c&")
|
4429
|
+
end
|
4430
|
+
|
4431
|
+
it "should have a compacted normalized query of 'a&c'" do
|
4432
|
+
expect(@uri.normalized_query(:compacted)).to eq("a&c")
|
4433
|
+
end
|
4434
|
+
end
|
4435
|
+
|
4436
|
+
describe Addressable::URI, "when parsed from 'http://example.com/?a=1&a=1'" do
|
4437
|
+
before do
|
4438
|
+
@uri = Addressable::URI.parse("http://example.com/?a=1&a=1")
|
4439
|
+
end
|
4440
|
+
|
4441
|
+
it "should have a compacted normalized query of 'a=1'" do
|
4442
|
+
expect(@uri.normalized_query(:compacted)).to eq("a=1")
|
4443
|
+
end
|
4444
|
+
end
|
4445
|
+
|
4446
|
+
describe Addressable::URI, "when parsed from 'http://example.com/?a=1&a=2'" do
|
4447
|
+
before do
|
4448
|
+
@uri = Addressable::URI.parse("http://example.com/?a=1&a=2")
|
4449
|
+
end
|
4450
|
+
|
4451
|
+
it "should have a compacted normalized query of 'a=1&a=2'" do
|
4452
|
+
expect(@uri.normalized_query(:compacted)).to eq("a=1&a=2")
|
4453
|
+
end
|
4454
|
+
end
|
4455
|
+
|
4306
4456
|
describe Addressable::URI, "when parsed from " +
|
4307
4457
|
"'http://example.com/sound%2bvision'" do
|
4308
4458
|
before do
|
@@ -4414,10 +4564,10 @@ describe Addressable::URI, "when parsed from " +
|
|
4414
4564
|
end
|
4415
4565
|
|
4416
4566
|
it "should raise an error after nil assignment of authority segment" do
|
4417
|
-
expect
|
4567
|
+
expect do
|
4418
4568
|
# This would create an invalid URI
|
4419
4569
|
@uri.authority = nil
|
4420
|
-
end
|
4570
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
4421
4571
|
end
|
4422
4572
|
end
|
4423
4573
|
|
@@ -4646,12 +4796,12 @@ describe Addressable::URI, "when parsed from " +
|
|
4646
4796
|
end
|
4647
4797
|
|
4648
4798
|
it "should raise an error if routing is attempted" do
|
4649
|
-
expect
|
4799
|
+
expect do
|
4650
4800
|
@uri.route_to("http://example.com/")
|
4651
|
-
end
|
4652
|
-
expect
|
4801
|
+
end.to raise_error(ArgumentError, /\/\/example.com\//)
|
4802
|
+
expect do
|
4653
4803
|
@uri.route_from("http://example.com/")
|
4654
|
-
end
|
4804
|
+
end.to raise_error(ArgumentError, /\/\/example.com\//)
|
4655
4805
|
end
|
4656
4806
|
|
4657
4807
|
it "should have a 'null' origin" do
|
@@ -4745,9 +4895,9 @@ end
|
|
4745
4895
|
describe Addressable::URI, "when parsed from " +
|
4746
4896
|
"'http://under_score.example.com/'" do
|
4747
4897
|
it "should not cause an error" do
|
4748
|
-
expect
|
4898
|
+
expect do
|
4749
4899
|
Addressable::URI.parse("http://under_score.example.com/")
|
4750
|
-
end
|
4900
|
+
end.not_to raise_error
|
4751
4901
|
end
|
4752
4902
|
end
|
4753
4903
|
|
@@ -4819,9 +4969,9 @@ describe Addressable::URI, "when parsed from '?one=1&two=2&three=3'" do
|
|
4819
4969
|
end
|
4820
4970
|
|
4821
4971
|
it "should raise an error for invalid return type values" do
|
4822
|
-
expect
|
4823
|
-
@uri.query_values(
|
4824
|
-
end
|
4972
|
+
expect do
|
4973
|
+
@uri.query_values(Integer)
|
4974
|
+
end.to raise_error(ArgumentError)
|
4825
4975
|
end
|
4826
4976
|
|
4827
4977
|
it "should have the correct array query values" do
|
@@ -5422,9 +5572,9 @@ describe Addressable::URI, "with a base uri of 'http://a/b/c/d;p?q'" do
|
|
5422
5572
|
end
|
5423
5573
|
|
5424
5574
|
it "when joined with a bogus object a TypeError should be raised" do
|
5425
|
-
expect
|
5575
|
+
expect do
|
5426
5576
|
Addressable::URI.join(@uri, 42)
|
5427
|
-
end
|
5577
|
+
end.to raise_error(TypeError)
|
5428
5578
|
end
|
5429
5579
|
end
|
5430
5580
|
|
@@ -5451,9 +5601,9 @@ end
|
|
5451
5601
|
|
5452
5602
|
describe Addressable::URI, "when converting a bogus path" do
|
5453
5603
|
it "should raise a TypeError" do
|
5454
|
-
expect
|
5604
|
+
expect do
|
5455
5605
|
Addressable::URI.convert_path(42)
|
5456
|
-
end
|
5606
|
+
end.to raise_error(TypeError)
|
5457
5607
|
end
|
5458
5608
|
end
|
5459
5609
|
|
@@ -5515,18 +5665,18 @@ describe Addressable::URI, "when given the tld " do
|
|
5515
5665
|
end
|
5516
5666
|
|
5517
5667
|
context "which " do
|
5518
|
-
let (:uri) { Addressable::URI.parse("http://comrade.net/path/to/source/") }
|
5668
|
+
let (:uri) { Addressable::URI.parse("http://www.comrade.net/path/to/source/") }
|
5519
5669
|
|
5520
5670
|
it "contains a subdomain" do
|
5521
5671
|
uri.tld = "co.uk"
|
5522
5672
|
|
5523
|
-
expect(uri.to_s).to eq("http://comrade.co.uk/path/to/source/")
|
5673
|
+
expect(uri.to_s).to eq("http://www.comrade.co.uk/path/to/source/")
|
5524
5674
|
end
|
5525
5675
|
|
5526
5676
|
it "is part of the domain" do
|
5527
5677
|
uri.tld = "com"
|
5528
5678
|
|
5529
|
-
expect(uri.to_s).to eq("http://comrade.com/path/to/source/")
|
5679
|
+
expect(uri.to_s).to eq("http://www.comrade.com/path/to/source/")
|
5530
5680
|
end
|
5531
5681
|
end
|
5532
5682
|
end
|
@@ -5648,9 +5798,9 @@ describe Addressable::URI, "when parsing a non-String object" do
|
|
5648
5798
|
end
|
5649
5799
|
|
5650
5800
|
it "should raise a TypeError for objects than cannot be converted" do
|
5651
|
-
expect
|
5801
|
+
expect do
|
5652
5802
|
Addressable::URI.parse(42)
|
5653
|
-
end
|
5803
|
+
end.to raise_error(TypeError)
|
5654
5804
|
end
|
5655
5805
|
|
5656
5806
|
it "should correctly parse heuristically anything with a 'to_str' method" do
|
@@ -5658,9 +5808,9 @@ describe Addressable::URI, "when parsing a non-String object" do
|
|
5658
5808
|
end
|
5659
5809
|
|
5660
5810
|
it "should raise a TypeError for objects than cannot be converted" do
|
5661
|
-
expect
|
5811
|
+
expect do
|
5662
5812
|
Addressable::URI.heuristic_parse(42)
|
5663
|
-
end
|
5813
|
+
end.to raise_error(TypeError)
|
5664
5814
|
end
|
5665
5815
|
end
|
5666
5816
|
|
@@ -5704,9 +5854,9 @@ end
|
|
5704
5854
|
|
5705
5855
|
describe Addressable::URI, "when form encoding a non-Array object" do
|
5706
5856
|
it "should raise a TypeError for objects than cannot be converted" do
|
5707
|
-
expect
|
5857
|
+
expect do
|
5708
5858
|
Addressable::URI.form_encode(42)
|
5709
|
-
end
|
5859
|
+
end.to raise_error(TypeError)
|
5710
5860
|
end
|
5711
5861
|
end
|
5712
5862
|
|
@@ -5772,9 +5922,9 @@ describe Addressable::URI, "when form unencoding a non-String object" do
|
|
5772
5922
|
end
|
5773
5923
|
|
5774
5924
|
it "should raise a TypeError for objects than cannot be converted" do
|
5775
|
-
expect
|
5925
|
+
expect do
|
5776
5926
|
Addressable::URI.form_unencode(42)
|
5777
|
-
end
|
5927
|
+
end.to raise_error(TypeError)
|
5778
5928
|
end
|
5779
5929
|
end
|
5780
5930
|
|
@@ -5784,15 +5934,15 @@ describe Addressable::URI, "when normalizing a non-String object" do
|
|
5784
5934
|
end
|
5785
5935
|
|
5786
5936
|
it "should raise a TypeError for objects than cannot be converted" do
|
5787
|
-
expect
|
5937
|
+
expect do
|
5788
5938
|
Addressable::URI.normalize_component(42)
|
5789
|
-
end
|
5939
|
+
end.to raise_error(TypeError)
|
5790
5940
|
end
|
5791
5941
|
|
5792
5942
|
it "should raise a TypeError for objects than cannot be converted" do
|
5793
|
-
expect
|
5943
|
+
expect do
|
5794
5944
|
Addressable::URI.normalize_component("component", 42)
|
5795
|
-
end
|
5945
|
+
end.to raise_error(TypeError)
|
5796
5946
|
end
|
5797
5947
|
end
|
5798
5948
|
|
@@ -5804,6 +5954,26 @@ describe Addressable::URI, "when normalizing a path with an encoded slash" do
|
|
5804
5954
|
end
|
5805
5955
|
end
|
5806
5956
|
|
5957
|
+
describe Addressable::URI, "when normalizing a path with special unicode" do
|
5958
|
+
it "does not stop at or ignore null bytes" do
|
5959
|
+
expect(Addressable::URI.parse("/path%00segment/").normalize.path).to eq(
|
5960
|
+
"/path%00segment/"
|
5961
|
+
)
|
5962
|
+
end
|
5963
|
+
|
5964
|
+
it "does apply NFC unicode normalization" do
|
5965
|
+
expect(Addressable::URI.parse("/%E2%84%A6").normalize.path).to eq(
|
5966
|
+
"/%CE%A9"
|
5967
|
+
)
|
5968
|
+
end
|
5969
|
+
|
5970
|
+
it "does not apply NFKC unicode normalization" do
|
5971
|
+
expect(Addressable::URI.parse("/%C2%AF%C2%A0").normalize.path).to eq(
|
5972
|
+
"/%C2%AF%C2%A0"
|
5973
|
+
)
|
5974
|
+
end
|
5975
|
+
end
|
5976
|
+
|
5807
5977
|
describe Addressable::URI, "when normalizing a partially encoded string" do
|
5808
5978
|
it "should result in correct percent encoded sequence" do
|
5809
5979
|
expect(Addressable::URI.normalize_component(
|
@@ -5864,6 +6034,18 @@ describe Addressable::URI, "when normalizing a string but leaving some character
|
|
5864
6034
|
end
|
5865
6035
|
end
|
5866
6036
|
|
6037
|
+
describe Addressable::URI, "when encoding IP literals" do
|
6038
|
+
it "should work for IPv4" do
|
6039
|
+
input = "http://127.0.0.1/"
|
6040
|
+
expect(Addressable::URI.encode(input)).to eq(input)
|
6041
|
+
end
|
6042
|
+
|
6043
|
+
it "should work for IPv6" do
|
6044
|
+
input = "http://[fe80::200:f8ff:fe21:67cf]/"
|
6045
|
+
expect(Addressable::URI.encode(input)).to eq(input)
|
6046
|
+
end
|
6047
|
+
end
|
6048
|
+
|
5867
6049
|
describe Addressable::URI, "when encoding a string with existing encodings to upcase" do
|
5868
6050
|
it "should result in correct percent encoded sequence" do
|
5869
6051
|
expect(Addressable::URI.encode_component("JK%4c", "0-9A-IKM-Za-z%", "L")).to eq("%4AK%4C")
|
@@ -5911,6 +6093,11 @@ describe Addressable::URI, "when unencoding a multibyte string" do
|
|
5911
6093
|
expect(Addressable::URI.unencode_component("ski=%BA%DAɫ")).to eq("ski=\xBA\xDAɫ")
|
5912
6094
|
end
|
5913
6095
|
|
6096
|
+
it "should not fail with UTF-8 incompatible string" do
|
6097
|
+
url = "/M%E9/\xE9?p=\xFC".b
|
6098
|
+
expect(Addressable::URI.unencode_component(url)).to eq("/M\xE9/\xE9?p=\xFC")
|
6099
|
+
end
|
6100
|
+
|
5914
6101
|
it "should result in correct percent encoded sequence as a URI" do
|
5915
6102
|
expect(Addressable::URI.unencode(
|
5916
6103
|
"/path?g%C3%BCnther", ::Addressable::URI
|
@@ -5936,41 +6123,41 @@ end
|
|
5936
6123
|
|
5937
6124
|
describe Addressable::URI, "when unencoding a bogus object" do
|
5938
6125
|
it "should raise a TypeError" do
|
5939
|
-
expect
|
6126
|
+
expect do
|
5940
6127
|
Addressable::URI.unencode_component(42)
|
5941
|
-
end
|
6128
|
+
end.to raise_error(TypeError)
|
5942
6129
|
end
|
5943
6130
|
|
5944
6131
|
it "should raise a TypeError" do
|
5945
|
-
expect
|
6132
|
+
expect do
|
5946
6133
|
Addressable::URI.unencode("/path?g%C3%BCnther", Integer)
|
5947
|
-
end
|
6134
|
+
end.to raise_error(TypeError)
|
5948
6135
|
end
|
5949
6136
|
end
|
5950
6137
|
|
5951
6138
|
describe Addressable::URI, "when encoding a bogus object" do
|
5952
6139
|
it "should raise a TypeError" do
|
5953
|
-
expect
|
6140
|
+
expect do
|
5954
6141
|
Addressable::URI.encode(Object.new)
|
5955
|
-
end
|
6142
|
+
end.to raise_error(TypeError)
|
5956
6143
|
end
|
5957
6144
|
|
5958
6145
|
it "should raise a TypeError" do
|
5959
|
-
expect
|
6146
|
+
expect do
|
5960
6147
|
Addressable::URI.normalized_encode(Object.new)
|
5961
|
-
end
|
6148
|
+
end.to raise_error(TypeError)
|
5962
6149
|
end
|
5963
6150
|
|
5964
6151
|
it "should raise a TypeError" do
|
5965
|
-
expect
|
6152
|
+
expect do
|
5966
6153
|
Addressable::URI.encode_component("günther", Object.new)
|
5967
|
-
end
|
6154
|
+
end.to raise_error(TypeError)
|
5968
6155
|
end
|
5969
6156
|
|
5970
6157
|
it "should raise a TypeError" do
|
5971
|
-
expect
|
6158
|
+
expect do
|
5972
6159
|
Addressable::URI.encode_component(Object.new)
|
5973
|
-
end
|
6160
|
+
end.to raise_error(TypeError)
|
5974
6161
|
end
|
5975
6162
|
end
|
5976
6163
|
|
@@ -5986,9 +6173,9 @@ describe Addressable::URI, "when given the input " +
|
|
5986
6173
|
end
|
5987
6174
|
|
5988
6175
|
it "should not raise error when frozen" do
|
5989
|
-
expect
|
6176
|
+
expect do
|
5990
6177
|
Addressable::URI.heuristic_parse(@input).freeze.to_s
|
5991
|
-
end
|
6178
|
+
end.not_to raise_error
|
5992
6179
|
end
|
5993
6180
|
end
|
5994
6181
|
|
@@ -6352,6 +6539,44 @@ describe Addressable::URI, "when given the input " +
|
|
6352
6539
|
end
|
6353
6540
|
end
|
6354
6541
|
|
6542
|
+
describe Addressable::URI, "when given the input: 'user@domain.com'" do
|
6543
|
+
before do
|
6544
|
+
@input = "user@domain.com"
|
6545
|
+
end
|
6546
|
+
|
6547
|
+
context "for heuristic parse" do
|
6548
|
+
it "should remain 'mailto:user@domain.com'" do
|
6549
|
+
uri = Addressable::URI.heuristic_parse("mailto:#{@input}")
|
6550
|
+
expect(uri.to_s).to eq("mailto:user@domain.com")
|
6551
|
+
end
|
6552
|
+
|
6553
|
+
it "should have a scheme of 'mailto'" do
|
6554
|
+
uri = Addressable::URI.heuristic_parse(@input)
|
6555
|
+
expect(uri.to_s).to eq("mailto:user@domain.com")
|
6556
|
+
expect(uri.scheme).to eq("mailto")
|
6557
|
+
end
|
6558
|
+
|
6559
|
+
it "should remain 'acct:user@domain.com'" do
|
6560
|
+
uri = Addressable::URI.heuristic_parse("acct:#{@input}")
|
6561
|
+
expect(uri.to_s).to eq("acct:user@domain.com")
|
6562
|
+
end
|
6563
|
+
|
6564
|
+
context "HTTP" do
|
6565
|
+
before do
|
6566
|
+
@uri = Addressable::URI.heuristic_parse("http://#{@input}/")
|
6567
|
+
end
|
6568
|
+
|
6569
|
+
it "should remain 'http://user@domain.com/'" do
|
6570
|
+
expect(@uri.to_s).to eq("http://user@domain.com/")
|
6571
|
+
end
|
6572
|
+
|
6573
|
+
it "should have the username 'user' for HTTP basic authentication" do
|
6574
|
+
expect(@uri.user).to eq("user")
|
6575
|
+
end
|
6576
|
+
end
|
6577
|
+
end
|
6578
|
+
end
|
6579
|
+
|
6355
6580
|
describe Addressable::URI, "when assigning query values" do
|
6356
6581
|
before do
|
6357
6582
|
@uri = Addressable::URI.new
|
@@ -6363,54 +6588,54 @@ describe Addressable::URI, "when assigning query values" do
|
|
6363
6588
|
end
|
6364
6589
|
|
6365
6590
|
it "should raise an error attempting to assign {'a' => {'b' => ['c']}}" do
|
6366
|
-
expect
|
6591
|
+
expect do
|
6367
6592
|
@uri.query_values = { 'a' => {'b' => ['c'] } }
|
6368
|
-
end
|
6593
|
+
end.to raise_error(TypeError)
|
6369
6594
|
end
|
6370
6595
|
|
6371
6596
|
it "should raise an error attempting to assign " +
|
6372
6597
|
"{:b => '2', :a => {:c => '1'}}" do
|
6373
|
-
expect
|
6598
|
+
expect do
|
6374
6599
|
@uri.query_values = {:b => '2', :a => {:c => '1'}}
|
6375
|
-
end
|
6600
|
+
end.to raise_error(TypeError)
|
6376
6601
|
end
|
6377
6602
|
|
6378
6603
|
it "should raise an error attempting to assign " +
|
6379
6604
|
"{:a => 'a', :b => [{:c => 'c', :d => 'd'}, " +
|
6380
6605
|
"{:e => 'e', :f => 'f'}]}" do
|
6381
|
-
expect
|
6606
|
+
expect do
|
6382
6607
|
@uri.query_values = {
|
6383
6608
|
:a => "a", :b => [{:c => "c", :d => "d"}, {:e => "e", :f => "f"}]
|
6384
6609
|
}
|
6385
|
-
end
|
6610
|
+
end.to raise_error(TypeError)
|
6386
6611
|
end
|
6387
6612
|
|
6388
6613
|
it "should raise an error attempting to assign " +
|
6389
6614
|
"{:a => 'a', :b => [{:c => true, :d => 'd'}, " +
|
6390
6615
|
"{:e => 'e', :f => 'f'}]}" do
|
6391
|
-
expect
|
6616
|
+
expect do
|
6392
6617
|
@uri.query_values = {
|
6393
6618
|
:a => 'a', :b => [{:c => true, :d => 'd'}, {:e => 'e', :f => 'f'}]
|
6394
6619
|
}
|
6395
|
-
end
|
6620
|
+
end.to raise_error(TypeError)
|
6396
6621
|
end
|
6397
6622
|
|
6398
6623
|
it "should raise an error attempting to assign " +
|
6399
6624
|
"{:a => 'a', :b => {:c => true, :d => 'd'}}" do
|
6400
|
-
expect
|
6625
|
+
expect do
|
6401
6626
|
@uri.query_values = {
|
6402
6627
|
:a => 'a', :b => {:c => true, :d => 'd'}
|
6403
6628
|
}
|
6404
|
-
end
|
6629
|
+
end.to raise_error(TypeError)
|
6405
6630
|
end
|
6406
6631
|
|
6407
6632
|
it "should raise an error attempting to assign " +
|
6408
6633
|
"{:a => 'a', :b => {:c => true, :d => 'd'}}" do
|
6409
|
-
expect
|
6634
|
+
expect do
|
6410
6635
|
@uri.query_values = {
|
6411
6636
|
:a => 'a', :b => {:c => true, :d => 'd'}
|
6412
6637
|
}
|
6413
|
-
end
|
6638
|
+
end.to raise_error(TypeError)
|
6414
6639
|
end
|
6415
6640
|
|
6416
6641
|
it "should correctly assign {:a => 1, :b => 1.5}" do
|
@@ -6421,13 +6646,13 @@ describe Addressable::URI, "when assigning query values" do
|
|
6421
6646
|
it "should raise an error attempting to assign " +
|
6422
6647
|
"{:z => 1, :f => [2, {999.1 => [3,'4']}, ['h', 'i']], " +
|
6423
6648
|
":a => {:b => ['c', 'd'], :e => true, :y => 0.5}}" do
|
6424
|
-
expect
|
6649
|
+
expect do
|
6425
6650
|
@uri.query_values = {
|
6426
6651
|
:z => 1,
|
6427
6652
|
:f => [ 2, {999.1 => [3,'4']}, ['h', 'i'] ],
|
6428
6653
|
:a => { :b => ['c', 'd'], :e => true, :y => 0.5 }
|
6429
6654
|
}
|
6430
|
-
end
|
6655
|
+
end.to raise_error(TypeError)
|
6431
6656
|
end
|
6432
6657
|
|
6433
6658
|
it "should correctly assign {}" do
|
@@ -6477,7 +6702,7 @@ describe Addressable::URI, "when assigning path values" do
|
|
6477
6702
|
@uri.path = "acct:bob@sporkmonger.com"
|
6478
6703
|
expect(@uri.path).to eq("acct:bob@sporkmonger.com")
|
6479
6704
|
expect(@uri.normalize.to_str).to eq("acct%2Fbob@sporkmonger.com")
|
6480
|
-
expect
|
6705
|
+
expect { @uri.to_s }.to raise_error(
|
6481
6706
|
Addressable::URI::InvalidURIError
|
6482
6707
|
)
|
6483
6708
|
end
|
@@ -6495,26 +6720,26 @@ describe Addressable::URI, "when assigning path values" do
|
|
6495
6720
|
end
|
6496
6721
|
|
6497
6722
|
it "should not allow relative paths to be assigned on absolute URIs" do
|
6498
|
-
expect
|
6723
|
+
expect do
|
6499
6724
|
@uri.scheme = "http"
|
6500
6725
|
@uri.host = "example.com"
|
6501
6726
|
@uri.path = "acct:bob@sporkmonger.com"
|
6502
|
-
end
|
6727
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
6503
6728
|
end
|
6504
6729
|
|
6505
6730
|
it "should not allow relative paths to be assigned on absolute URIs" do
|
6506
|
-
expect
|
6731
|
+
expect do
|
6507
6732
|
@uri.path = "acct:bob@sporkmonger.com"
|
6508
6733
|
@uri.scheme = "http"
|
6509
6734
|
@uri.host = "example.com"
|
6510
|
-
end
|
6735
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
6511
6736
|
end
|
6512
6737
|
|
6513
6738
|
it "should not allow relative paths to be assigned on absolute URIs" do
|
6514
|
-
expect
|
6739
|
+
expect do
|
6515
6740
|
@uri.path = "uuid:0b3ecf60-3f93-11df-a9c3-001f5bfffe12"
|
6516
6741
|
@uri.scheme = "urn"
|
6517
|
-
end
|
6742
|
+
end.not_to raise_error
|
6518
6743
|
end
|
6519
6744
|
end
|
6520
6745
|
|
@@ -6543,3 +6768,73 @@ describe Addressable::URI, "when initializing a subclass of Addressable::URI" do
|
|
6543
6768
|
expect(@uri.class).to eq(@uri.join('path').class)
|
6544
6769
|
end
|
6545
6770
|
end
|
6771
|
+
|
6772
|
+
describe Addressable::URI, "support serialization roundtrip" do
|
6773
|
+
before do
|
6774
|
+
@uri = Addressable::URI.new(
|
6775
|
+
:scheme => "http",
|
6776
|
+
:user => "user",
|
6777
|
+
:password => "password",
|
6778
|
+
:host => "example.com",
|
6779
|
+
:port => 80,
|
6780
|
+
:path => "/path",
|
6781
|
+
:query => "query=value",
|
6782
|
+
:fragment => "fragment"
|
6783
|
+
)
|
6784
|
+
end
|
6785
|
+
|
6786
|
+
it "is in a working state after being serialized with Marshal" do
|
6787
|
+
@uri = Addressable::URI.parse("http://example.com")
|
6788
|
+
cloned_uri = Marshal.load(Marshal.dump(@uri))
|
6789
|
+
expect(cloned_uri.normalized_scheme).to be == @uri.normalized_scheme
|
6790
|
+
end
|
6791
|
+
|
6792
|
+
it "is in a working state after being serialized with YAML" do
|
6793
|
+
@uri = Addressable::URI.parse("http://example.com")
|
6794
|
+
cloned_uri = if YAML.respond_to?(:unsafe_load)
|
6795
|
+
YAML.unsafe_load(YAML.dump(@uri))
|
6796
|
+
else
|
6797
|
+
YAML.load(YAML.dump(@uri))
|
6798
|
+
end
|
6799
|
+
expect(cloned_uri.normalized_scheme).to be == @uri.normalized_scheme
|
6800
|
+
end
|
6801
|
+
end
|
6802
|
+
|
6803
|
+
describe Addressable::URI, "when initialized in a non-main `Ractor`" do
|
6804
|
+
it "should have the same value as if used in the main `Ractor`" do
|
6805
|
+
pending("Ruby 3.0+ for `Ractor` support") unless defined?(Ractor)
|
6806
|
+
main = Addressable::URI.parse("http://example.com")
|
6807
|
+
expect(
|
6808
|
+
Ractor.new { Addressable::URI.parse("http://example.com") }.take
|
6809
|
+
).to eq(main)
|
6810
|
+
end
|
6811
|
+
end
|
6812
|
+
|
6813
|
+
describe Addressable::URI, "when deferring validation" do
|
6814
|
+
subject(:deferred) { uri.instance_variable_get(:@validation_deferred) }
|
6815
|
+
|
6816
|
+
let(:uri) { Addressable::URI.parse("http://example.com") }
|
6817
|
+
|
6818
|
+
it "defers validation within the block" do
|
6819
|
+
uri.defer_validation do
|
6820
|
+
expect(deferred).to be true
|
6821
|
+
end
|
6822
|
+
end
|
6823
|
+
|
6824
|
+
it "always resets deferral afterward" do
|
6825
|
+
expect { uri.defer_validation { raise "boom" } }.to raise_error("boom")
|
6826
|
+
expect(deferred).to be false
|
6827
|
+
end
|
6828
|
+
|
6829
|
+
it "returns nil" do
|
6830
|
+
res = uri.defer_validation {}
|
6831
|
+
expect(res).to be nil
|
6832
|
+
end
|
6833
|
+
end
|
6834
|
+
|
6835
|
+
describe Addressable::URI, "YAML safe loading" do
|
6836
|
+
it "doesn't serialize anonymous objects" do
|
6837
|
+
url = Addressable::URI.parse("http://example.com/")
|
6838
|
+
expect(YAML.dump(url)).to_not include("!ruby/object {}")
|
6839
|
+
end
|
6840
|
+
end
|