addressable 2.6.0 → 2.8.1
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 +35 -0
- data/Gemfile +14 -16
- data/README.md +12 -10
- data/Rakefile +3 -3
- data/lib/addressable/idna/native.rb +0 -1
- data/lib/addressable/idna/pure.rb +52 -51
- data/lib/addressable/idna.rb +0 -1
- data/lib/addressable/template.rb +28 -43
- data/lib/addressable/uri.rb +129 -79
- data/lib/addressable/version.rb +2 -3
- data/spec/addressable/idna_spec.rb +3 -2
- data/spec/addressable/net_http_compat_spec.rb +0 -1
- data/spec/addressable/security_spec.rb +0 -1
- data/spec/addressable/template_spec.rb +18 -1
- data/spec/addressable/uri_spec.rb +408 -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 +15 -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");
|
@@ -65,116 +64,116 @@ end
|
|
65
64
|
|
66
65
|
describe Addressable::URI, "when created with a non-numeric port number" do
|
67
66
|
it "should raise an error" do
|
68
|
-
expect
|
67
|
+
expect do
|
69
68
|
Addressable::URI.new(:port => "bogus")
|
70
|
-
end
|
69
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
71
70
|
end
|
72
71
|
end
|
73
72
|
|
74
73
|
describe Addressable::URI, "when created with a invalid encoded port number" do
|
75
74
|
it "should raise an error" do
|
76
|
-
expect
|
75
|
+
expect do
|
77
76
|
Addressable::URI.new(:port => "%eb")
|
78
|
-
end
|
77
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
79
78
|
end
|
80
79
|
end
|
81
80
|
|
82
81
|
describe Addressable::URI, "when created with a non-string scheme" do
|
83
82
|
it "should raise an error" do
|
84
|
-
expect
|
83
|
+
expect do
|
85
84
|
Addressable::URI.new(:scheme => :bogus)
|
86
|
-
end
|
85
|
+
end.to raise_error(TypeError)
|
87
86
|
end
|
88
87
|
end
|
89
88
|
|
90
89
|
describe Addressable::URI, "when created with a non-string user" do
|
91
90
|
it "should raise an error" do
|
92
|
-
expect
|
91
|
+
expect do
|
93
92
|
Addressable::URI.new(:user => :bogus)
|
94
|
-
end
|
93
|
+
end.to raise_error(TypeError)
|
95
94
|
end
|
96
95
|
end
|
97
96
|
|
98
97
|
describe Addressable::URI, "when created with a non-string password" do
|
99
98
|
it "should raise an error" do
|
100
|
-
expect
|
99
|
+
expect do
|
101
100
|
Addressable::URI.new(:password => :bogus)
|
102
|
-
end
|
101
|
+
end.to raise_error(TypeError)
|
103
102
|
end
|
104
103
|
end
|
105
104
|
|
106
105
|
describe Addressable::URI, "when created with a non-string userinfo" do
|
107
106
|
it "should raise an error" do
|
108
|
-
expect
|
107
|
+
expect do
|
109
108
|
Addressable::URI.new(:userinfo => :bogus)
|
110
|
-
end
|
109
|
+
end.to raise_error(TypeError)
|
111
110
|
end
|
112
111
|
end
|
113
112
|
|
114
113
|
describe Addressable::URI, "when created with a non-string host" do
|
115
114
|
it "should raise an error" do
|
116
|
-
expect
|
115
|
+
expect do
|
117
116
|
Addressable::URI.new(:host => :bogus)
|
118
|
-
end
|
117
|
+
end.to raise_error(TypeError)
|
119
118
|
end
|
120
119
|
end
|
121
120
|
|
122
121
|
describe Addressable::URI, "when created with a non-string authority" do
|
123
122
|
it "should raise an error" do
|
124
|
-
expect
|
123
|
+
expect do
|
125
124
|
Addressable::URI.new(:authority => :bogus)
|
126
|
-
end
|
125
|
+
end.to raise_error(TypeError)
|
127
126
|
end
|
128
127
|
end
|
129
128
|
|
130
129
|
describe Addressable::URI, "when created with a non-string path" do
|
131
130
|
it "should raise an error" do
|
132
|
-
expect
|
131
|
+
expect do
|
133
132
|
Addressable::URI.new(:path => :bogus)
|
134
|
-
end
|
133
|
+
end.to raise_error(TypeError)
|
135
134
|
end
|
136
135
|
end
|
137
136
|
|
138
137
|
describe Addressable::URI, "when created with a non-string query" do
|
139
138
|
it "should raise an error" do
|
140
|
-
expect
|
139
|
+
expect do
|
141
140
|
Addressable::URI.new(:query => :bogus)
|
142
|
-
end
|
141
|
+
end.to raise_error(TypeError)
|
143
142
|
end
|
144
143
|
end
|
145
144
|
|
146
145
|
describe Addressable::URI, "when created with a non-string fragment" do
|
147
146
|
it "should raise an error" do
|
148
|
-
expect
|
147
|
+
expect do
|
149
148
|
Addressable::URI.new(:fragment => :bogus)
|
150
|
-
end
|
149
|
+
end.to raise_error(TypeError)
|
151
150
|
end
|
152
151
|
end
|
153
152
|
|
154
153
|
describe Addressable::URI, "when created with a scheme but no hierarchical " +
|
155
154
|
"segment" do
|
156
155
|
it "should raise an error" do
|
157
|
-
expect
|
156
|
+
expect do
|
158
157
|
Addressable::URI.parse("http:")
|
159
|
-
end
|
158
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
160
159
|
end
|
161
160
|
end
|
162
161
|
|
163
162
|
describe Addressable::URI, "quote handling" do
|
164
163
|
describe 'in host name' do
|
165
164
|
it "should raise an error for single quote" do
|
166
|
-
expect
|
165
|
+
expect do
|
167
166
|
Addressable::URI.parse("http://local\"host/")
|
168
|
-
end
|
167
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
169
168
|
end
|
170
169
|
end
|
171
170
|
end
|
172
171
|
|
173
172
|
describe Addressable::URI, "newline normalization" do
|
174
173
|
it "should not accept newlines in scheme" do
|
175
|
-
expect
|
174
|
+
expect do
|
176
175
|
Addressable::URI.parse("ht%0atp://localhost/")
|
177
|
-
end
|
176
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
178
177
|
end
|
179
178
|
|
180
179
|
it "should not unescape newline in path" do
|
@@ -199,47 +198,47 @@ describe Addressable::URI, "newline normalization" do
|
|
199
198
|
|
200
199
|
it "should not accept newline in hostname" do
|
201
200
|
uri = Addressable::URI.parse("http://localhost/")
|
202
|
-
expect
|
201
|
+
expect do
|
203
202
|
uri.host = "local\nhost"
|
204
|
-
end
|
203
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
205
204
|
end
|
206
205
|
end
|
207
206
|
|
208
207
|
describe Addressable::URI, "when created with ambiguous path" do
|
209
208
|
it "should raise an error" do
|
210
|
-
expect
|
209
|
+
expect do
|
211
210
|
Addressable::URI.parse("::http")
|
212
|
-
end
|
211
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
213
212
|
end
|
214
213
|
end
|
215
214
|
|
216
215
|
describe Addressable::URI, "when created with an invalid host" do
|
217
216
|
it "should raise an error" do
|
218
|
-
expect
|
217
|
+
expect do
|
219
218
|
Addressable::URI.new(:host => "<invalid>")
|
220
|
-
end
|
219
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
221
220
|
end
|
222
221
|
end
|
223
222
|
|
224
223
|
describe Addressable::URI, "when created with a host consisting of " +
|
225
224
|
"sub-delims characters" do
|
226
225
|
it "should not raise an error" do
|
227
|
-
expect
|
226
|
+
expect do
|
228
227
|
Addressable::URI.new(
|
229
228
|
:host => Addressable::URI::CharacterClasses::SUB_DELIMS.gsub(/\\/, '')
|
230
229
|
)
|
231
|
-
end
|
230
|
+
end.not_to raise_error
|
232
231
|
end
|
233
232
|
end
|
234
233
|
|
235
234
|
describe Addressable::URI, "when created with a host consisting of " +
|
236
235
|
"unreserved characters" do
|
237
236
|
it "should not raise an error" do
|
238
|
-
expect
|
237
|
+
expect do
|
239
238
|
Addressable::URI.new(
|
240
239
|
:host => Addressable::URI::CharacterClasses::UNRESERVED.gsub(/\\/, '')
|
241
240
|
)
|
242
|
-
end
|
241
|
+
end.not_to raise_error
|
243
242
|
end
|
244
243
|
end
|
245
244
|
|
@@ -269,83 +268,83 @@ describe Addressable::URI, "when created from nil components" do
|
|
269
268
|
end
|
270
269
|
|
271
270
|
it "should raise an error if the scheme is set to whitespace" do
|
272
|
-
expect
|
271
|
+
expect do
|
273
272
|
@uri.scheme = "\t \n"
|
274
|
-
end
|
273
|
+
end.to raise_error(Addressable::URI::InvalidURIError, /'\t \n'/)
|
275
274
|
end
|
276
275
|
|
277
276
|
it "should raise an error if the scheme is set to all digits" do
|
278
|
-
expect
|
277
|
+
expect do
|
279
278
|
@uri.scheme = "123"
|
280
|
-
end
|
279
|
+
end.to raise_error(Addressable::URI::InvalidURIError, /'123'/)
|
281
280
|
end
|
282
281
|
|
283
282
|
it "should raise an error if the scheme begins with a digit" do
|
284
|
-
expect
|
283
|
+
expect do
|
285
284
|
@uri.scheme = "1scheme"
|
286
|
-
end
|
285
|
+
end.to raise_error(Addressable::URI::InvalidURIError, /'1scheme'/)
|
287
286
|
end
|
288
287
|
|
289
288
|
it "should raise an error if the scheme begins with a plus" do
|
290
|
-
expect
|
289
|
+
expect do
|
291
290
|
@uri.scheme = "+scheme"
|
292
|
-
end
|
291
|
+
end.to raise_error(Addressable::URI::InvalidURIError, /'\+scheme'/)
|
293
292
|
end
|
294
293
|
|
295
294
|
it "should raise an error if the scheme begins with a dot" do
|
296
|
-
expect
|
295
|
+
expect do
|
297
296
|
@uri.scheme = ".scheme"
|
298
|
-
end
|
297
|
+
end.to raise_error(Addressable::URI::InvalidURIError, /'\.scheme'/)
|
299
298
|
end
|
300
299
|
|
301
300
|
it "should raise an error if the scheme begins with a dash" do
|
302
|
-
expect
|
301
|
+
expect do
|
303
302
|
@uri.scheme = "-scheme"
|
304
|
-
end
|
303
|
+
end.to raise_error(Addressable::URI::InvalidURIError, /'-scheme'/)
|
305
304
|
end
|
306
305
|
|
307
306
|
it "should raise an error if the scheme contains an illegal character" do
|
308
|
-
expect
|
307
|
+
expect do
|
309
308
|
@uri.scheme = "scheme!"
|
310
|
-
end
|
309
|
+
end.to raise_error(Addressable::URI::InvalidURIError, /'scheme!'/)
|
311
310
|
end
|
312
311
|
|
313
312
|
it "should raise an error if the scheme contains whitespace" do
|
314
|
-
expect
|
313
|
+
expect do
|
315
314
|
@uri.scheme = "sch eme"
|
316
|
-
end
|
315
|
+
end.to raise_error(Addressable::URI::InvalidURIError, /'sch eme'/)
|
317
316
|
end
|
318
317
|
|
319
318
|
it "should raise an error if the scheme contains a newline" do
|
320
|
-
expect
|
319
|
+
expect do
|
321
320
|
@uri.scheme = "sch\neme"
|
322
|
-
end
|
321
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
323
322
|
end
|
324
323
|
|
325
324
|
it "should raise an error if set into an invalid state" do
|
326
|
-
expect
|
325
|
+
expect do
|
327
326
|
@uri.user = "user"
|
328
|
-
end
|
327
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
329
328
|
end
|
330
329
|
|
331
330
|
it "should raise an error if set into an invalid state" do
|
332
|
-
expect
|
331
|
+
expect do
|
333
332
|
@uri.password = "pass"
|
334
|
-
end
|
333
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
335
334
|
end
|
336
335
|
|
337
336
|
it "should raise an error if set into an invalid state" do
|
338
|
-
expect
|
337
|
+
expect do
|
339
338
|
@uri.scheme = "http"
|
340
339
|
@uri.fragment = "fragment"
|
341
|
-
end
|
340
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
342
341
|
end
|
343
342
|
|
344
343
|
it "should raise an error if set into an invalid state" do
|
345
|
-
expect
|
344
|
+
expect do
|
346
345
|
@uri.fragment = "fragment"
|
347
346
|
@uri.scheme = "http"
|
348
|
-
end
|
347
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
349
348
|
end
|
350
349
|
end
|
351
350
|
|
@@ -999,6 +998,72 @@ describe Addressable::URI, "when frozen" do
|
|
999
998
|
end
|
1000
999
|
end
|
1001
1000
|
|
1001
|
+
describe Addressable::URI, "when normalized and then deeply frozen" do
|
1002
|
+
before do
|
1003
|
+
@uri = Addressable::URI.parse(
|
1004
|
+
"http://user:password@example.com:8080/path?query=value#fragment"
|
1005
|
+
).normalize!
|
1006
|
+
|
1007
|
+
@uri.instance_variables.each do |var|
|
1008
|
+
@uri.instance_variable_set(var, @uri.instance_variable_get(var).freeze)
|
1009
|
+
end
|
1010
|
+
|
1011
|
+
@uri.freeze
|
1012
|
+
end
|
1013
|
+
|
1014
|
+
it "#normalized_scheme should not error" do
|
1015
|
+
expect { @uri.normalized_scheme }.not_to raise_error
|
1016
|
+
end
|
1017
|
+
|
1018
|
+
it "#normalized_user should not error" do
|
1019
|
+
expect { @uri.normalized_user }.not_to raise_error
|
1020
|
+
end
|
1021
|
+
|
1022
|
+
it "#normalized_password should not error" do
|
1023
|
+
expect { @uri.normalized_password }.not_to raise_error
|
1024
|
+
end
|
1025
|
+
|
1026
|
+
it "#normalized_userinfo should not error" do
|
1027
|
+
expect { @uri.normalized_userinfo }.not_to raise_error
|
1028
|
+
end
|
1029
|
+
|
1030
|
+
it "#normalized_host should not error" do
|
1031
|
+
expect { @uri.normalized_host }.not_to raise_error
|
1032
|
+
end
|
1033
|
+
|
1034
|
+
it "#normalized_authority should not error" do
|
1035
|
+
expect { @uri.normalized_authority }.not_to raise_error
|
1036
|
+
end
|
1037
|
+
|
1038
|
+
it "#normalized_port should not error" do
|
1039
|
+
expect { @uri.normalized_port }.not_to raise_error
|
1040
|
+
end
|
1041
|
+
|
1042
|
+
it "#normalized_site should not error" do
|
1043
|
+
expect { @uri.normalized_site }.not_to raise_error
|
1044
|
+
end
|
1045
|
+
|
1046
|
+
it "#normalized_path should not error" do
|
1047
|
+
expect { @uri.normalized_path }.not_to raise_error
|
1048
|
+
end
|
1049
|
+
|
1050
|
+
it "#normalized_query should not error" do
|
1051
|
+
expect { @uri.normalized_query }.not_to raise_error
|
1052
|
+
end
|
1053
|
+
|
1054
|
+
it "#normalized_fragment should not error" do
|
1055
|
+
expect { @uri.normalized_fragment }.not_to raise_error
|
1056
|
+
end
|
1057
|
+
|
1058
|
+
it "should be frozen" do
|
1059
|
+
expect(@uri).to be_frozen
|
1060
|
+
end
|
1061
|
+
|
1062
|
+
it "should not allow destructive operations" do
|
1063
|
+
expect { @uri.normalize! }.to raise_error(RuntimeError)
|
1064
|
+
end
|
1065
|
+
end
|
1066
|
+
|
1002
1067
|
describe Addressable::URI, "when created from string components" do
|
1003
1068
|
before do
|
1004
1069
|
@uri = Addressable::URI.new(
|
@@ -1015,31 +1080,31 @@ describe Addressable::URI, "when created from string components" do
|
|
1015
1080
|
end
|
1016
1081
|
|
1017
1082
|
it "should raise an error if invalid components omitted" do
|
1018
|
-
expect
|
1083
|
+
expect do
|
1019
1084
|
@uri.omit(:bogus)
|
1020
|
-
end
|
1021
|
-
expect
|
1085
|
+
end.to raise_error(ArgumentError)
|
1086
|
+
expect do
|
1022
1087
|
@uri.omit(:scheme, :bogus, :path)
|
1023
|
-
end
|
1088
|
+
end.to raise_error(ArgumentError)
|
1024
1089
|
end
|
1025
1090
|
end
|
1026
1091
|
|
1027
1092
|
describe Addressable::URI, "when created with a nil host but " +
|
1028
1093
|
"non-nil authority components" do
|
1029
1094
|
it "should raise an error" do
|
1030
|
-
expect
|
1095
|
+
expect do
|
1031
1096
|
Addressable::URI.new(:user => "user", :password => "pass", :port => 80)
|
1032
|
-
end
|
1097
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
1033
1098
|
end
|
1034
1099
|
end
|
1035
1100
|
|
1036
1101
|
describe Addressable::URI, "when created with both an authority and a user" do
|
1037
1102
|
it "should raise an error" do
|
1038
|
-
expect
|
1103
|
+
expect do
|
1039
1104
|
Addressable::URI.new(
|
1040
1105
|
:user => "user", :authority => "user@example.com:80"
|
1041
1106
|
)
|
1042
|
-
end
|
1107
|
+
end.to raise_error(ArgumentError)
|
1043
1108
|
end
|
1044
1109
|
end
|
1045
1110
|
|
@@ -1077,33 +1142,33 @@ end
|
|
1077
1142
|
|
1078
1143
|
describe Addressable::URI, "when created with a host with a backslash" do
|
1079
1144
|
it "should raise an error" do
|
1080
|
-
expect
|
1145
|
+
expect do
|
1081
1146
|
Addressable::URI.new(:authority => "example\\example")
|
1082
|
-
end
|
1147
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
1083
1148
|
end
|
1084
1149
|
end
|
1085
1150
|
|
1086
1151
|
describe Addressable::URI, "when created with a host with a slash" do
|
1087
1152
|
it "should raise an error" do
|
1088
|
-
expect
|
1153
|
+
expect do
|
1089
1154
|
Addressable::URI.new(:authority => "example/example")
|
1090
|
-
end
|
1155
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
1091
1156
|
end
|
1092
1157
|
end
|
1093
1158
|
|
1094
1159
|
describe Addressable::URI, "when created with a host with a space" do
|
1095
1160
|
it "should raise an error" do
|
1096
|
-
expect
|
1161
|
+
expect do
|
1097
1162
|
Addressable::URI.new(:authority => "example example")
|
1098
|
-
end
|
1163
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
1099
1164
|
end
|
1100
1165
|
end
|
1101
1166
|
|
1102
1167
|
describe Addressable::URI, "when created with both a userinfo and a user" do
|
1103
1168
|
it "should raise an error" do
|
1104
|
-
expect
|
1169
|
+
expect do
|
1105
1170
|
Addressable::URI.new(:user => "user", :userinfo => "user:pass")
|
1106
|
-
end
|
1171
|
+
end.to raise_error(ArgumentError)
|
1107
1172
|
end
|
1108
1173
|
end
|
1109
1174
|
|
@@ -1195,18 +1260,18 @@ describe Addressable::URI, "when parsed from something that looks " +
|
|
1195
1260
|
"like a URI object" do
|
1196
1261
|
it "should parse without error" do
|
1197
1262
|
uri = Addressable::URI.parse(Fake::URI::HTTP.new("http://example.com/"))
|
1198
|
-
expect
|
1263
|
+
expect do
|
1199
1264
|
Addressable::URI.parse(uri)
|
1200
|
-
end
|
1265
|
+
end.not_to raise_error
|
1201
1266
|
end
|
1202
1267
|
end
|
1203
1268
|
|
1204
1269
|
describe Addressable::URI, "when parsed from a standard library URI object" do
|
1205
1270
|
it "should parse without error" do
|
1206
1271
|
uri = Addressable::URI.parse(URI.parse("http://example.com/"))
|
1207
|
-
expect
|
1272
|
+
expect do
|
1208
1273
|
Addressable::URI.parse(uri)
|
1209
|
-
end
|
1274
|
+
end.not_to raise_error
|
1210
1275
|
end
|
1211
1276
|
end
|
1212
1277
|
|
@@ -1366,9 +1431,9 @@ describe Addressable::URI, "when parsed from " +
|
|
1366
1431
|
end
|
1367
1432
|
|
1368
1433
|
it "should not allow request URI assignment" do
|
1369
|
-
expect
|
1434
|
+
expect do
|
1370
1435
|
@uri.request_uri = "/"
|
1371
|
-
end
|
1436
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
1372
1437
|
end
|
1373
1438
|
|
1374
1439
|
it "should have a query of 'objectClass?one'" do
|
@@ -1390,9 +1455,9 @@ describe Addressable::URI, "when parsed from " +
|
|
1390
1455
|
end
|
1391
1456
|
|
1392
1457
|
it "should raise an error if omission would create an invalid URI" do
|
1393
|
-
expect
|
1458
|
+
expect do
|
1394
1459
|
@uri.omit(:authority, :path)
|
1395
|
-
end
|
1460
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
1396
1461
|
end
|
1397
1462
|
|
1398
1463
|
it "should have an origin of 'ldap://[2001:db8::7]'" do
|
@@ -1778,9 +1843,9 @@ describe Addressable::URI, "when parsed from " +
|
|
1778
1843
|
|
1779
1844
|
it "should not be roughly equal to the string " +
|
1780
1845
|
"'http://example.com:bogus/'" do
|
1781
|
-
expect
|
1846
|
+
expect do
|
1782
1847
|
expect(@uri === "http://example.com:bogus/").to eq(false)
|
1783
|
-
end
|
1848
|
+
end.not_to raise_error
|
1784
1849
|
end
|
1785
1850
|
|
1786
1851
|
it "should result in itself when joined with itself" do
|
@@ -1810,21 +1875,21 @@ describe Addressable::URI, "when parsed from " +
|
|
1810
1875
|
end
|
1811
1876
|
|
1812
1877
|
it "should not allow origin assignment without scheme" do
|
1813
|
-
expect
|
1878
|
+
expect do
|
1814
1879
|
@uri.origin = "example.com"
|
1815
|
-
end
|
1880
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
1816
1881
|
end
|
1817
1882
|
|
1818
1883
|
it "should not allow origin assignment without host" do
|
1819
|
-
expect
|
1884
|
+
expect do
|
1820
1885
|
@uri.origin = "http://"
|
1821
|
-
end
|
1886
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
1822
1887
|
end
|
1823
1888
|
|
1824
1889
|
it "should not allow origin assignment with bogus type" do
|
1825
|
-
expect
|
1890
|
+
expect do
|
1826
1891
|
@uri.origin = :bogus
|
1827
|
-
end
|
1892
|
+
end.to raise_error(TypeError)
|
1828
1893
|
end
|
1829
1894
|
|
1830
1895
|
# Section 6.2.3 of RFC 3986
|
@@ -1880,9 +1945,9 @@ describe Addressable::URI, "when parsed from " +
|
|
1880
1945
|
end
|
1881
1946
|
|
1882
1947
|
it "when joined with a bogus object a TypeError should be raised" do
|
1883
|
-
expect
|
1948
|
+
expect do
|
1884
1949
|
@uri.join(42)
|
1885
|
-
end
|
1950
|
+
end.to raise_error(TypeError)
|
1886
1951
|
end
|
1887
1952
|
|
1888
1953
|
it "should have the correct username after assignment" do
|
@@ -2015,15 +2080,15 @@ describe Addressable::URI, "when parsed from " +
|
|
2015
2080
|
end
|
2016
2081
|
|
2017
2082
|
it "should raise an error if the site value is set to something bogus" do
|
2018
|
-
expect
|
2083
|
+
expect do
|
2019
2084
|
@uri.site = 42
|
2020
|
-
end
|
2085
|
+
end.to raise_error(TypeError)
|
2021
2086
|
end
|
2022
2087
|
|
2023
2088
|
it "should raise an error if the request URI is set to something bogus" do
|
2024
|
-
expect
|
2089
|
+
expect do
|
2025
2090
|
@uri.request_uri = 42
|
2026
|
-
end
|
2091
|
+
end.to raise_error(TypeError)
|
2027
2092
|
end
|
2028
2093
|
|
2029
2094
|
it "should correctly convert to a hash" do
|
@@ -2072,9 +2137,9 @@ describe Addressable::URI, "when parsing IPv6 addresses" do
|
|
2072
2137
|
|
2073
2138
|
it "should raise an error for " +
|
2074
2139
|
"'http://[<invalid>]/'" do
|
2075
|
-
expect
|
2140
|
+
expect do
|
2076
2141
|
Addressable::URI.parse("http://[<invalid>]/")
|
2077
|
-
end
|
2142
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
2078
2143
|
end
|
2079
2144
|
end
|
2080
2145
|
|
@@ -2100,9 +2165,9 @@ describe Addressable::URI, "when assigning IPv6 address" do
|
|
2100
2165
|
it "should not allow to set bare IPv6 address as host" do
|
2101
2166
|
uri = Addressable::URI.parse("http://[::1]/")
|
2102
2167
|
skip "not checked"
|
2103
|
-
expect
|
2168
|
+
expect do
|
2104
2169
|
uri.host = '3ffe:1900:4545:3:200:f8ff:fe21:67cf'
|
2105
|
-
end
|
2170
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
2106
2171
|
end
|
2107
2172
|
end
|
2108
2173
|
|
@@ -2134,9 +2199,9 @@ describe Addressable::URI, "when parsing IPvFuture addresses" do
|
|
2134
2199
|
|
2135
2200
|
it "should raise an error for " +
|
2136
2201
|
"'http://[v0.<invalid>]/'" do
|
2137
|
-
expect
|
2202
|
+
expect do
|
2138
2203
|
Addressable::URI.parse("http://[v0.<invalid>]/")
|
2139
|
-
end
|
2204
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
2140
2205
|
end
|
2141
2206
|
end
|
2142
2207
|
|
@@ -2480,9 +2545,9 @@ describe Addressable::URI, "when parsed from " +
|
|
2480
2545
|
end
|
2481
2546
|
|
2482
2547
|
it "should not raise an exception when normalized" do
|
2483
|
-
expect
|
2548
|
+
expect do
|
2484
2549
|
@uri.normalize
|
2485
|
-
end
|
2550
|
+
end.not_to raise_error
|
2486
2551
|
end
|
2487
2552
|
|
2488
2553
|
it "should be considered to be in normal form" do
|
@@ -2534,9 +2599,9 @@ describe Addressable::URI, "when parsed from " +
|
|
2534
2599
|
end
|
2535
2600
|
|
2536
2601
|
it "should not raise an exception when normalized" do
|
2537
|
-
expect
|
2602
|
+
expect do
|
2538
2603
|
@uri.normalize
|
2539
|
-
end
|
2604
|
+
end.not_to raise_error
|
2540
2605
|
end
|
2541
2606
|
|
2542
2607
|
it "should be considered to be in normal form" do
|
@@ -2559,9 +2624,9 @@ describe Addressable::URI, "when parsed from " +
|
|
2559
2624
|
end
|
2560
2625
|
|
2561
2626
|
it "should not raise an exception when normalized" do
|
2562
|
-
expect
|
2627
|
+
expect do
|
2563
2628
|
@uri.normalize
|
2564
|
-
end
|
2629
|
+
end.not_to raise_error
|
2565
2630
|
end
|
2566
2631
|
|
2567
2632
|
it "should be considered to be in normal form" do
|
@@ -2597,9 +2662,9 @@ describe Addressable::URI, "when parsed from " +
|
|
2597
2662
|
end
|
2598
2663
|
|
2599
2664
|
it "should raise an error if encoding with an unexpected return type" do
|
2600
|
-
expect
|
2665
|
+
expect do
|
2601
2666
|
Addressable::URI.normalized_encode(@uri, Integer)
|
2602
|
-
end
|
2667
|
+
end.to raise_error(TypeError)
|
2603
2668
|
end
|
2604
2669
|
|
2605
2670
|
it "if percent encoded should be 'http://example.com/C%25CC%25A7'" do
|
@@ -2615,9 +2680,9 @@ describe Addressable::URI, "when parsed from " +
|
|
2615
2680
|
end
|
2616
2681
|
|
2617
2682
|
it "should raise an error if encoding with an unexpected return type" do
|
2618
|
-
expect
|
2683
|
+
expect do
|
2619
2684
|
Addressable::URI.encode(@uri, Integer)
|
2620
|
-
end
|
2685
|
+
end.to raise_error(TypeError)
|
2621
2686
|
end
|
2622
2687
|
|
2623
2688
|
it "should be identical to its duplicate" do
|
@@ -2752,9 +2817,9 @@ describe Addressable::URI, "when parsed from " +
|
|
2752
2817
|
|
2753
2818
|
it "should not be roughly equal to the string " +
|
2754
2819
|
"'http://example.com:bogus/'" do
|
2755
|
-
expect
|
2820
|
+
expect do
|
2756
2821
|
expect(@uri === "http://example.com:bogus/").to eq(false)
|
2757
|
-
end
|
2822
|
+
end.not_to raise_error
|
2758
2823
|
end
|
2759
2824
|
|
2760
2825
|
it "should result in itself when joined with itself" do
|
@@ -3100,9 +3165,9 @@ describe Addressable::URI, "when parsed from " +
|
|
3100
3165
|
end
|
3101
3166
|
|
3102
3167
|
it "should become invalid when normalized" do
|
3103
|
-
expect
|
3168
|
+
expect do
|
3104
3169
|
@uri.normalize
|
3105
|
-
end
|
3170
|
+
end.to raise_error(Addressable::URI::InvalidURIError, /authority/)
|
3106
3171
|
end
|
3107
3172
|
|
3108
3173
|
it "should have a path of '/..//example.com'" do
|
@@ -3340,12 +3405,12 @@ describe Addressable::URI, "when parsed from " +
|
|
3340
3405
|
end
|
3341
3406
|
|
3342
3407
|
it "should raise an error if routing is attempted" do
|
3343
|
-
expect
|
3408
|
+
expect do
|
3344
3409
|
@uri.route_to("http://example.com/")
|
3345
|
-
end
|
3346
|
-
expect
|
3410
|
+
end.to raise_error(ArgumentError, /relative\/path\/to\/resource/)
|
3411
|
+
expect do
|
3347
3412
|
@uri.route_from("http://example.com/")
|
3348
|
-
end
|
3413
|
+
end.to raise_error(ArgumentError, /relative\/path\/to\/resource/)
|
3349
3414
|
end
|
3350
3415
|
|
3351
3416
|
it "when joined with 'another/relative/path' should be " +
|
@@ -3942,9 +4007,9 @@ describe Addressable::URI, "when parsed from " +
|
|
3942
4007
|
end
|
3943
4008
|
|
3944
4009
|
it "should raise an error if assigning a bogus object to the hostname" do
|
3945
|
-
expect
|
4010
|
+
expect do
|
3946
4011
|
@uri.hostname = Object.new
|
3947
|
-
end
|
4012
|
+
end.to raise_error(TypeError)
|
3948
4013
|
end
|
3949
4014
|
|
3950
4015
|
it "should have the correct port after assignment" do
|
@@ -4023,9 +4088,9 @@ describe Addressable::URI, "when parsed from " +
|
|
4023
4088
|
end
|
4024
4089
|
|
4025
4090
|
it "should raise an error if query values are set to a bogus type" do
|
4026
|
-
expect
|
4091
|
+
expect do
|
4027
4092
|
@uri.query_values = "bogus"
|
4028
|
-
end
|
4093
|
+
end.to raise_error(TypeError)
|
4029
4094
|
end
|
4030
4095
|
|
4031
4096
|
it "should have the correct fragment after assignment" do
|
@@ -4097,39 +4162,39 @@ describe Addressable::URI, "when parsed from " +
|
|
4097
4162
|
end
|
4098
4163
|
|
4099
4164
|
it "should fail to merge with bogus values" do
|
4100
|
-
expect
|
4165
|
+
expect do
|
4101
4166
|
@uri.merge(:port => "bogus")
|
4102
|
-
end
|
4167
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
4103
4168
|
end
|
4104
4169
|
|
4105
4170
|
it "should fail to merge with bogus values" do
|
4106
|
-
expect
|
4171
|
+
expect do
|
4107
4172
|
@uri.merge(:authority => "bar@baz:bogus")
|
4108
|
-
end
|
4173
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
4109
4174
|
end
|
4110
4175
|
|
4111
4176
|
it "should fail to merge with bogus parameters" do
|
4112
|
-
expect
|
4177
|
+
expect do
|
4113
4178
|
@uri.merge(42)
|
4114
|
-
end
|
4179
|
+
end.to raise_error(TypeError)
|
4115
4180
|
end
|
4116
4181
|
|
4117
4182
|
it "should fail to merge with bogus parameters" do
|
4118
|
-
expect
|
4183
|
+
expect do
|
4119
4184
|
@uri.merge("http://example.com/")
|
4120
|
-
end
|
4185
|
+
end.to raise_error(TypeError)
|
4121
4186
|
end
|
4122
4187
|
|
4123
4188
|
it "should fail to merge with both authority and subcomponents" do
|
4124
|
-
expect
|
4189
|
+
expect do
|
4125
4190
|
@uri.merge(:authority => "foo:bar@baz:42", :port => "42")
|
4126
|
-
end
|
4191
|
+
end.to raise_error(ArgumentError)
|
4127
4192
|
end
|
4128
4193
|
|
4129
4194
|
it "should fail to merge with both userinfo and subcomponents" do
|
4130
|
-
expect
|
4195
|
+
expect do
|
4131
4196
|
@uri.merge(:userinfo => "foo:bar", :user => "foo")
|
4132
|
-
end
|
4197
|
+
end.to raise_error(ArgumentError)
|
4133
4198
|
end
|
4134
4199
|
|
4135
4200
|
it "should be identical to its duplicate" do
|
@@ -4262,6 +4327,36 @@ describe Addressable::URI, "when parsed from " +
|
|
4262
4327
|
end
|
4263
4328
|
end
|
4264
4329
|
|
4330
|
+
describe Addressable::URI, "when parsed from 'https://example.com/?q=a+b'" do
|
4331
|
+
before do
|
4332
|
+
@uri = Addressable::URI.parse("https://example.com/?q=a+b")
|
4333
|
+
end
|
4334
|
+
|
4335
|
+
it "should have query_values of {'q' => 'a b'}" do
|
4336
|
+
expect(@uri.query_values).to eq("q" => "a b")
|
4337
|
+
end
|
4338
|
+
end
|
4339
|
+
|
4340
|
+
describe Addressable::URI, "when parsed from 'example.com?q=a+b'" do
|
4341
|
+
before do
|
4342
|
+
@uri = Addressable::URI.parse("example.com?q=a+b")
|
4343
|
+
end
|
4344
|
+
|
4345
|
+
it "should have query_values of {'q' => 'a b'}" do
|
4346
|
+
expect(@uri.query_values).to eq("q" => "a b")
|
4347
|
+
end
|
4348
|
+
end
|
4349
|
+
|
4350
|
+
describe Addressable::URI, "when parsed from 'mailto:?q=a+b'" do
|
4351
|
+
before do
|
4352
|
+
@uri = Addressable::URI.parse("mailto:?q=a+b")
|
4353
|
+
end
|
4354
|
+
|
4355
|
+
it "should have query_values of {'q' => 'a+b'}" do
|
4356
|
+
expect(@uri.query_values).to eq("q" => "a+b")
|
4357
|
+
end
|
4358
|
+
end
|
4359
|
+
|
4265
4360
|
describe Addressable::URI, "when parsed from " +
|
4266
4361
|
"'http://example.com/?q=a%2bb'" do
|
4267
4362
|
before do
|
@@ -4303,6 +4398,46 @@ describe Addressable::URI, "when parsed from " +
|
|
4303
4398
|
end
|
4304
4399
|
end
|
4305
4400
|
|
4401
|
+
describe Addressable::URI, "when parsed from 'http://example/?b=1&a=2&c=3'" do
|
4402
|
+
before do
|
4403
|
+
@uri = Addressable::URI.parse("http://example/?b=1&a=2&c=3")
|
4404
|
+
end
|
4405
|
+
|
4406
|
+
it "should have a sorted normalized query of 'a=2&b=1&c=3'" do
|
4407
|
+
expect(@uri.normalized_query(:sorted)).to eq("a=2&b=1&c=3")
|
4408
|
+
end
|
4409
|
+
end
|
4410
|
+
|
4411
|
+
describe Addressable::URI, "when parsed from 'http://example/?&a&&c&'" do
|
4412
|
+
before do
|
4413
|
+
@uri = Addressable::URI.parse("http://example/?&a&&c&")
|
4414
|
+
end
|
4415
|
+
|
4416
|
+
it "should have a compacted normalized query of 'a&c'" do
|
4417
|
+
expect(@uri.normalized_query(:compacted)).to eq("a&c")
|
4418
|
+
end
|
4419
|
+
end
|
4420
|
+
|
4421
|
+
describe Addressable::URI, "when parsed from 'http://example.com/?a=1&a=1'" do
|
4422
|
+
before do
|
4423
|
+
@uri = Addressable::URI.parse("http://example.com/?a=1&a=1")
|
4424
|
+
end
|
4425
|
+
|
4426
|
+
it "should have a compacted normalized query of 'a=1'" do
|
4427
|
+
expect(@uri.normalized_query(:compacted)).to eq("a=1")
|
4428
|
+
end
|
4429
|
+
end
|
4430
|
+
|
4431
|
+
describe Addressable::URI, "when parsed from 'http://example.com/?a=1&a=2'" do
|
4432
|
+
before do
|
4433
|
+
@uri = Addressable::URI.parse("http://example.com/?a=1&a=2")
|
4434
|
+
end
|
4435
|
+
|
4436
|
+
it "should have a compacted normalized query of 'a=1&a=2'" do
|
4437
|
+
expect(@uri.normalized_query(:compacted)).to eq("a=1&a=2")
|
4438
|
+
end
|
4439
|
+
end
|
4440
|
+
|
4306
4441
|
describe Addressable::URI, "when parsed from " +
|
4307
4442
|
"'http://example.com/sound%2bvision'" do
|
4308
4443
|
before do
|
@@ -4414,10 +4549,10 @@ describe Addressable::URI, "when parsed from " +
|
|
4414
4549
|
end
|
4415
4550
|
|
4416
4551
|
it "should raise an error after nil assignment of authority segment" do
|
4417
|
-
expect
|
4552
|
+
expect do
|
4418
4553
|
# This would create an invalid URI
|
4419
4554
|
@uri.authority = nil
|
4420
|
-
end
|
4555
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
4421
4556
|
end
|
4422
4557
|
end
|
4423
4558
|
|
@@ -4646,12 +4781,12 @@ describe Addressable::URI, "when parsed from " +
|
|
4646
4781
|
end
|
4647
4782
|
|
4648
4783
|
it "should raise an error if routing is attempted" do
|
4649
|
-
expect
|
4784
|
+
expect do
|
4650
4785
|
@uri.route_to("http://example.com/")
|
4651
|
-
end
|
4652
|
-
expect
|
4786
|
+
end.to raise_error(ArgumentError, /\/\/example.com\//)
|
4787
|
+
expect do
|
4653
4788
|
@uri.route_from("http://example.com/")
|
4654
|
-
end
|
4789
|
+
end.to raise_error(ArgumentError, /\/\/example.com\//)
|
4655
4790
|
end
|
4656
4791
|
|
4657
4792
|
it "should have a 'null' origin" do
|
@@ -4745,9 +4880,9 @@ end
|
|
4745
4880
|
describe Addressable::URI, "when parsed from " +
|
4746
4881
|
"'http://under_score.example.com/'" do
|
4747
4882
|
it "should not cause an error" do
|
4748
|
-
expect
|
4883
|
+
expect do
|
4749
4884
|
Addressable::URI.parse("http://under_score.example.com/")
|
4750
|
-
end
|
4885
|
+
end.not_to raise_error
|
4751
4886
|
end
|
4752
4887
|
end
|
4753
4888
|
|
@@ -4819,9 +4954,9 @@ describe Addressable::URI, "when parsed from '?one=1&two=2&three=3'" do
|
|
4819
4954
|
end
|
4820
4955
|
|
4821
4956
|
it "should raise an error for invalid return type values" do
|
4822
|
-
expect
|
4823
|
-
@uri.query_values(
|
4824
|
-
end
|
4957
|
+
expect do
|
4958
|
+
@uri.query_values(Integer)
|
4959
|
+
end.to raise_error(ArgumentError)
|
4825
4960
|
end
|
4826
4961
|
|
4827
4962
|
it "should have the correct array query values" do
|
@@ -5422,9 +5557,9 @@ describe Addressable::URI, "with a base uri of 'http://a/b/c/d;p?q'" do
|
|
5422
5557
|
end
|
5423
5558
|
|
5424
5559
|
it "when joined with a bogus object a TypeError should be raised" do
|
5425
|
-
expect
|
5560
|
+
expect do
|
5426
5561
|
Addressable::URI.join(@uri, 42)
|
5427
|
-
end
|
5562
|
+
end.to raise_error(TypeError)
|
5428
5563
|
end
|
5429
5564
|
end
|
5430
5565
|
|
@@ -5451,9 +5586,9 @@ end
|
|
5451
5586
|
|
5452
5587
|
describe Addressable::URI, "when converting a bogus path" do
|
5453
5588
|
it "should raise a TypeError" do
|
5454
|
-
expect
|
5589
|
+
expect do
|
5455
5590
|
Addressable::URI.convert_path(42)
|
5456
|
-
end
|
5591
|
+
end.to raise_error(TypeError)
|
5457
5592
|
end
|
5458
5593
|
end
|
5459
5594
|
|
@@ -5515,18 +5650,18 @@ describe Addressable::URI, "when given the tld " do
|
|
5515
5650
|
end
|
5516
5651
|
|
5517
5652
|
context "which " do
|
5518
|
-
let (:uri) { Addressable::URI.parse("http://comrade.net/path/to/source/") }
|
5653
|
+
let (:uri) { Addressable::URI.parse("http://www.comrade.net/path/to/source/") }
|
5519
5654
|
|
5520
5655
|
it "contains a subdomain" do
|
5521
5656
|
uri.tld = "co.uk"
|
5522
5657
|
|
5523
|
-
expect(uri.to_s).to eq("http://comrade.co.uk/path/to/source/")
|
5658
|
+
expect(uri.to_s).to eq("http://www.comrade.co.uk/path/to/source/")
|
5524
5659
|
end
|
5525
5660
|
|
5526
5661
|
it "is part of the domain" do
|
5527
5662
|
uri.tld = "com"
|
5528
5663
|
|
5529
|
-
expect(uri.to_s).to eq("http://comrade.com/path/to/source/")
|
5664
|
+
expect(uri.to_s).to eq("http://www.comrade.com/path/to/source/")
|
5530
5665
|
end
|
5531
5666
|
end
|
5532
5667
|
end
|
@@ -5648,9 +5783,9 @@ describe Addressable::URI, "when parsing a non-String object" do
|
|
5648
5783
|
end
|
5649
5784
|
|
5650
5785
|
it "should raise a TypeError for objects than cannot be converted" do
|
5651
|
-
expect
|
5786
|
+
expect do
|
5652
5787
|
Addressable::URI.parse(42)
|
5653
|
-
end
|
5788
|
+
end.to raise_error(TypeError)
|
5654
5789
|
end
|
5655
5790
|
|
5656
5791
|
it "should correctly parse heuristically anything with a 'to_str' method" do
|
@@ -5658,9 +5793,9 @@ describe Addressable::URI, "when parsing a non-String object" do
|
|
5658
5793
|
end
|
5659
5794
|
|
5660
5795
|
it "should raise a TypeError for objects than cannot be converted" do
|
5661
|
-
expect
|
5796
|
+
expect do
|
5662
5797
|
Addressable::URI.heuristic_parse(42)
|
5663
|
-
end
|
5798
|
+
end.to raise_error(TypeError)
|
5664
5799
|
end
|
5665
5800
|
end
|
5666
5801
|
|
@@ -5704,9 +5839,9 @@ end
|
|
5704
5839
|
|
5705
5840
|
describe Addressable::URI, "when form encoding a non-Array object" do
|
5706
5841
|
it "should raise a TypeError for objects than cannot be converted" do
|
5707
|
-
expect
|
5842
|
+
expect do
|
5708
5843
|
Addressable::URI.form_encode(42)
|
5709
|
-
end
|
5844
|
+
end.to raise_error(TypeError)
|
5710
5845
|
end
|
5711
5846
|
end
|
5712
5847
|
|
@@ -5772,9 +5907,9 @@ describe Addressable::URI, "when form unencoding a non-String object" do
|
|
5772
5907
|
end
|
5773
5908
|
|
5774
5909
|
it "should raise a TypeError for objects than cannot be converted" do
|
5775
|
-
expect
|
5910
|
+
expect do
|
5776
5911
|
Addressable::URI.form_unencode(42)
|
5777
|
-
end
|
5912
|
+
end.to raise_error(TypeError)
|
5778
5913
|
end
|
5779
5914
|
end
|
5780
5915
|
|
@@ -5784,15 +5919,15 @@ describe Addressable::URI, "when normalizing a non-String object" do
|
|
5784
5919
|
end
|
5785
5920
|
|
5786
5921
|
it "should raise a TypeError for objects than cannot be converted" do
|
5787
|
-
expect
|
5922
|
+
expect do
|
5788
5923
|
Addressable::URI.normalize_component(42)
|
5789
|
-
end
|
5924
|
+
end.to raise_error(TypeError)
|
5790
5925
|
end
|
5791
5926
|
|
5792
5927
|
it "should raise a TypeError for objects than cannot be converted" do
|
5793
|
-
expect
|
5928
|
+
expect do
|
5794
5929
|
Addressable::URI.normalize_component("component", 42)
|
5795
|
-
end
|
5930
|
+
end.to raise_error(TypeError)
|
5796
5931
|
end
|
5797
5932
|
end
|
5798
5933
|
|
@@ -5864,6 +5999,18 @@ describe Addressable::URI, "when normalizing a string but leaving some character
|
|
5864
5999
|
end
|
5865
6000
|
end
|
5866
6001
|
|
6002
|
+
describe Addressable::URI, "when encoding IP literals" do
|
6003
|
+
it "should work for IPv4" do
|
6004
|
+
input = "http://127.0.0.1/"
|
6005
|
+
expect(Addressable::URI.encode(input)).to eq(input)
|
6006
|
+
end
|
6007
|
+
|
6008
|
+
it "should work for IPv6" do
|
6009
|
+
input = "http://[fe80::200:f8ff:fe21:67cf]/"
|
6010
|
+
expect(Addressable::URI.encode(input)).to eq(input)
|
6011
|
+
end
|
6012
|
+
end
|
6013
|
+
|
5867
6014
|
describe Addressable::URI, "when encoding a string with existing encodings to upcase" do
|
5868
6015
|
it "should result in correct percent encoded sequence" do
|
5869
6016
|
expect(Addressable::URI.encode_component("JK%4c", "0-9A-IKM-Za-z%", "L")).to eq("%4AK%4C")
|
@@ -5911,6 +6058,11 @@ describe Addressable::URI, "when unencoding a multibyte string" do
|
|
5911
6058
|
expect(Addressable::URI.unencode_component("ski=%BA%DAɫ")).to eq("ski=\xBA\xDAɫ")
|
5912
6059
|
end
|
5913
6060
|
|
6061
|
+
it "should not fail with UTF-8 incompatible string" do
|
6062
|
+
url = "/M%E9/\xE9?p=\xFC".b
|
6063
|
+
expect(Addressable::URI.unencode_component(url)).to eq("/M\xE9/\xE9?p=\xFC")
|
6064
|
+
end
|
6065
|
+
|
5914
6066
|
it "should result in correct percent encoded sequence as a URI" do
|
5915
6067
|
expect(Addressable::URI.unencode(
|
5916
6068
|
"/path?g%C3%BCnther", ::Addressable::URI
|
@@ -5936,41 +6088,41 @@ end
|
|
5936
6088
|
|
5937
6089
|
describe Addressable::URI, "when unencoding a bogus object" do
|
5938
6090
|
it "should raise a TypeError" do
|
5939
|
-
expect
|
6091
|
+
expect do
|
5940
6092
|
Addressable::URI.unencode_component(42)
|
5941
|
-
end
|
6093
|
+
end.to raise_error(TypeError)
|
5942
6094
|
end
|
5943
6095
|
|
5944
6096
|
it "should raise a TypeError" do
|
5945
|
-
expect
|
6097
|
+
expect do
|
5946
6098
|
Addressable::URI.unencode("/path?g%C3%BCnther", Integer)
|
5947
|
-
end
|
6099
|
+
end.to raise_error(TypeError)
|
5948
6100
|
end
|
5949
6101
|
end
|
5950
6102
|
|
5951
6103
|
describe Addressable::URI, "when encoding a bogus object" do
|
5952
6104
|
it "should raise a TypeError" do
|
5953
|
-
expect
|
6105
|
+
expect do
|
5954
6106
|
Addressable::URI.encode(Object.new)
|
5955
|
-
end
|
6107
|
+
end.to raise_error(TypeError)
|
5956
6108
|
end
|
5957
6109
|
|
5958
6110
|
it "should raise a TypeError" do
|
5959
|
-
expect
|
6111
|
+
expect do
|
5960
6112
|
Addressable::URI.normalized_encode(Object.new)
|
5961
|
-
end
|
6113
|
+
end.to raise_error(TypeError)
|
5962
6114
|
end
|
5963
6115
|
|
5964
6116
|
it "should raise a TypeError" do
|
5965
|
-
expect
|
6117
|
+
expect do
|
5966
6118
|
Addressable::URI.encode_component("günther", Object.new)
|
5967
|
-
end
|
6119
|
+
end.to raise_error(TypeError)
|
5968
6120
|
end
|
5969
6121
|
|
5970
6122
|
it "should raise a TypeError" do
|
5971
|
-
expect
|
6123
|
+
expect do
|
5972
6124
|
Addressable::URI.encode_component(Object.new)
|
5973
|
-
end
|
6125
|
+
end.to raise_error(TypeError)
|
5974
6126
|
end
|
5975
6127
|
end
|
5976
6128
|
|
@@ -5986,9 +6138,9 @@ describe Addressable::URI, "when given the input " +
|
|
5986
6138
|
end
|
5987
6139
|
|
5988
6140
|
it "should not raise error when frozen" do
|
5989
|
-
expect
|
6141
|
+
expect do
|
5990
6142
|
Addressable::URI.heuristic_parse(@input).freeze.to_s
|
5991
|
-
end
|
6143
|
+
end.not_to raise_error
|
5992
6144
|
end
|
5993
6145
|
end
|
5994
6146
|
|
@@ -6352,6 +6504,44 @@ describe Addressable::URI, "when given the input " +
|
|
6352
6504
|
end
|
6353
6505
|
end
|
6354
6506
|
|
6507
|
+
describe Addressable::URI, "when given the input: 'user@domain.com'" do
|
6508
|
+
before do
|
6509
|
+
@input = "user@domain.com"
|
6510
|
+
end
|
6511
|
+
|
6512
|
+
context "for heuristic parse" do
|
6513
|
+
it "should remain 'mailto:user@domain.com'" do
|
6514
|
+
uri = Addressable::URI.heuristic_parse("mailto:#{@input}")
|
6515
|
+
expect(uri.to_s).to eq("mailto:user@domain.com")
|
6516
|
+
end
|
6517
|
+
|
6518
|
+
it "should have a scheme of 'mailto'" do
|
6519
|
+
uri = Addressable::URI.heuristic_parse(@input)
|
6520
|
+
expect(uri.to_s).to eq("mailto:user@domain.com")
|
6521
|
+
expect(uri.scheme).to eq("mailto")
|
6522
|
+
end
|
6523
|
+
|
6524
|
+
it "should remain 'acct:user@domain.com'" do
|
6525
|
+
uri = Addressable::URI.heuristic_parse("acct:#{@input}")
|
6526
|
+
expect(uri.to_s).to eq("acct:user@domain.com")
|
6527
|
+
end
|
6528
|
+
|
6529
|
+
context "HTTP" do
|
6530
|
+
before do
|
6531
|
+
@uri = Addressable::URI.heuristic_parse("http://#{@input}/")
|
6532
|
+
end
|
6533
|
+
|
6534
|
+
it "should remain 'http://user@domain.com/'" do
|
6535
|
+
expect(@uri.to_s).to eq("http://user@domain.com/")
|
6536
|
+
end
|
6537
|
+
|
6538
|
+
it "should have the username 'user' for HTTP basic authentication" do
|
6539
|
+
expect(@uri.user).to eq("user")
|
6540
|
+
end
|
6541
|
+
end
|
6542
|
+
end
|
6543
|
+
end
|
6544
|
+
|
6355
6545
|
describe Addressable::URI, "when assigning query values" do
|
6356
6546
|
before do
|
6357
6547
|
@uri = Addressable::URI.new
|
@@ -6363,54 +6553,54 @@ describe Addressable::URI, "when assigning query values" do
|
|
6363
6553
|
end
|
6364
6554
|
|
6365
6555
|
it "should raise an error attempting to assign {'a' => {'b' => ['c']}}" do
|
6366
|
-
expect
|
6556
|
+
expect do
|
6367
6557
|
@uri.query_values = { 'a' => {'b' => ['c'] } }
|
6368
|
-
end
|
6558
|
+
end.to raise_error(TypeError)
|
6369
6559
|
end
|
6370
6560
|
|
6371
6561
|
it "should raise an error attempting to assign " +
|
6372
6562
|
"{:b => '2', :a => {:c => '1'}}" do
|
6373
|
-
expect
|
6563
|
+
expect do
|
6374
6564
|
@uri.query_values = {:b => '2', :a => {:c => '1'}}
|
6375
|
-
end
|
6565
|
+
end.to raise_error(TypeError)
|
6376
6566
|
end
|
6377
6567
|
|
6378
6568
|
it "should raise an error attempting to assign " +
|
6379
6569
|
"{:a => 'a', :b => [{:c => 'c', :d => 'd'}, " +
|
6380
6570
|
"{:e => 'e', :f => 'f'}]}" do
|
6381
|
-
expect
|
6571
|
+
expect do
|
6382
6572
|
@uri.query_values = {
|
6383
6573
|
:a => "a", :b => [{:c => "c", :d => "d"}, {:e => "e", :f => "f"}]
|
6384
6574
|
}
|
6385
|
-
end
|
6575
|
+
end.to raise_error(TypeError)
|
6386
6576
|
end
|
6387
6577
|
|
6388
6578
|
it "should raise an error attempting to assign " +
|
6389
6579
|
"{:a => 'a', :b => [{:c => true, :d => 'd'}, " +
|
6390
6580
|
"{:e => 'e', :f => 'f'}]}" do
|
6391
|
-
expect
|
6581
|
+
expect do
|
6392
6582
|
@uri.query_values = {
|
6393
6583
|
:a => 'a', :b => [{:c => true, :d => 'd'}, {:e => 'e', :f => 'f'}]
|
6394
6584
|
}
|
6395
|
-
end
|
6585
|
+
end.to raise_error(TypeError)
|
6396
6586
|
end
|
6397
6587
|
|
6398
6588
|
it "should raise an error attempting to assign " +
|
6399
6589
|
"{:a => 'a', :b => {:c => true, :d => 'd'}}" do
|
6400
|
-
expect
|
6590
|
+
expect do
|
6401
6591
|
@uri.query_values = {
|
6402
6592
|
:a => 'a', :b => {:c => true, :d => 'd'}
|
6403
6593
|
}
|
6404
|
-
end
|
6594
|
+
end.to raise_error(TypeError)
|
6405
6595
|
end
|
6406
6596
|
|
6407
6597
|
it "should raise an error attempting to assign " +
|
6408
6598
|
"{:a => 'a', :b => {:c => true, :d => 'd'}}" do
|
6409
|
-
expect
|
6599
|
+
expect do
|
6410
6600
|
@uri.query_values = {
|
6411
6601
|
:a => 'a', :b => {:c => true, :d => 'd'}
|
6412
6602
|
}
|
6413
|
-
end
|
6603
|
+
end.to raise_error(TypeError)
|
6414
6604
|
end
|
6415
6605
|
|
6416
6606
|
it "should correctly assign {:a => 1, :b => 1.5}" do
|
@@ -6421,13 +6611,13 @@ describe Addressable::URI, "when assigning query values" do
|
|
6421
6611
|
it "should raise an error attempting to assign " +
|
6422
6612
|
"{:z => 1, :f => [2, {999.1 => [3,'4']}, ['h', 'i']], " +
|
6423
6613
|
":a => {:b => ['c', 'd'], :e => true, :y => 0.5}}" do
|
6424
|
-
expect
|
6614
|
+
expect do
|
6425
6615
|
@uri.query_values = {
|
6426
6616
|
:z => 1,
|
6427
6617
|
:f => [ 2, {999.1 => [3,'4']}, ['h', 'i'] ],
|
6428
6618
|
:a => { :b => ['c', 'd'], :e => true, :y => 0.5 }
|
6429
6619
|
}
|
6430
|
-
end
|
6620
|
+
end.to raise_error(TypeError)
|
6431
6621
|
end
|
6432
6622
|
|
6433
6623
|
it "should correctly assign {}" do
|
@@ -6477,7 +6667,7 @@ describe Addressable::URI, "when assigning path values" do
|
|
6477
6667
|
@uri.path = "acct:bob@sporkmonger.com"
|
6478
6668
|
expect(@uri.path).to eq("acct:bob@sporkmonger.com")
|
6479
6669
|
expect(@uri.normalize.to_str).to eq("acct%2Fbob@sporkmonger.com")
|
6480
|
-
expect
|
6670
|
+
expect { @uri.to_s }.to raise_error(
|
6481
6671
|
Addressable::URI::InvalidURIError
|
6482
6672
|
)
|
6483
6673
|
end
|
@@ -6495,26 +6685,26 @@ describe Addressable::URI, "when assigning path values" do
|
|
6495
6685
|
end
|
6496
6686
|
|
6497
6687
|
it "should not allow relative paths to be assigned on absolute URIs" do
|
6498
|
-
expect
|
6688
|
+
expect do
|
6499
6689
|
@uri.scheme = "http"
|
6500
6690
|
@uri.host = "example.com"
|
6501
6691
|
@uri.path = "acct:bob@sporkmonger.com"
|
6502
|
-
end
|
6692
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
6503
6693
|
end
|
6504
6694
|
|
6505
6695
|
it "should not allow relative paths to be assigned on absolute URIs" do
|
6506
|
-
expect
|
6696
|
+
expect do
|
6507
6697
|
@uri.path = "acct:bob@sporkmonger.com"
|
6508
6698
|
@uri.scheme = "http"
|
6509
6699
|
@uri.host = "example.com"
|
6510
|
-
end
|
6700
|
+
end.to raise_error(Addressable::URI::InvalidURIError)
|
6511
6701
|
end
|
6512
6702
|
|
6513
6703
|
it "should not allow relative paths to be assigned on absolute URIs" do
|
6514
|
-
expect
|
6704
|
+
expect do
|
6515
6705
|
@uri.path = "uuid:0b3ecf60-3f93-11df-a9c3-001f5bfffe12"
|
6516
6706
|
@uri.scheme = "urn"
|
6517
|
-
end
|
6707
|
+
end.not_to raise_error
|
6518
6708
|
end
|
6519
6709
|
end
|
6520
6710
|
|
@@ -6543,3 +6733,13 @@ describe Addressable::URI, "when initializing a subclass of Addressable::URI" do
|
|
6543
6733
|
expect(@uri.class).to eq(@uri.join('path').class)
|
6544
6734
|
end
|
6545
6735
|
end
|
6736
|
+
|
6737
|
+
describe Addressable::URI, "when initialized in a non-main `Ractor`" do
|
6738
|
+
it "should have the same value as if used in the main `Ractor`" do
|
6739
|
+
pending("Ruby 3.0+ for `Ractor` support") unless defined?(Ractor)
|
6740
|
+
main = Addressable::URI.parse("http://example.com")
|
6741
|
+
expect(
|
6742
|
+
Ractor.new { Addressable::URI.parse("http://example.com") }.take
|
6743
|
+
).to eq(main)
|
6744
|
+
end
|
6745
|
+
end
|