File tree 2 files changed +30
-15
lines changed 2 files changed +30
-15
lines changed Original file line number Diff line number Diff line change @@ -656,9 +656,12 @@ defmodule URI do
656
656
scheme = String . downcase ( scheme , :ascii )
657
657
658
658
case map do
659
- % { port: port } when port != :undefined ->
659
+ % { port: port } when is_integer ( port ) ->
660
660
% { uri | scheme: scheme }
661
661
662
+ % { port: :undefined } ->
663
+ % { uri | scheme: scheme , port: default_port ( scheme ) }
664
+
662
665
% { } ->
663
666
case default_port ( scheme ) do
664
667
nil -> % { uri | scheme: scheme }
Original file line number Diff line number Diff line change @@ -97,20 +97,6 @@ defmodule URITest do
97
97
assert URI . new ( "" ) == { :ok , % URI { } }
98
98
end
99
99
100
- test "missing port part after host never resolves to :undefined" do
101
- assert URI . new ( "//https://www.example.com" ) ==
102
- { :ok ,
103
- % URI {
104
- scheme: nil ,
105
- userinfo: nil ,
106
- host: "https" ,
107
- port: nil ,
108
- path: "//www.example.com" ,
109
- query: nil ,
110
- fragment: nil
111
- } }
112
- end
113
-
114
100
test "errors on bad URIs" do
115
101
assert URI . new ( "/>" ) == { :error , ">" }
116
102
assert URI . new ( ":https" ) == { :error , ":" }
@@ -291,6 +277,32 @@ defmodule URITest do
291
277
test "preserves an empty query" do
292
278
assert URI . new! ( "http://foo.com/?" ) . query == ""
293
279
end
280
+
281
+ test "without scheme, undefined port after host translates to nil" do
282
+ assert URI . new! ( "//https://www.example.com" ) ==
283
+ % URI {
284
+ scheme: nil ,
285
+ userinfo: nil ,
286
+ host: "https" ,
287
+ port: nil ,
288
+ path: "//www.example.com" ,
289
+ query: nil ,
290
+ fragment: nil
291
+ }
292
+ end
293
+
294
+ test "with scheme, undefined port after host translates to nil" do
295
+ assert URI . new! ( "myscheme://myhost:/path/info" ) ==
296
+ % URI {
297
+ scheme: "myscheme" ,
298
+ userinfo: nil ,
299
+ host: "myhost" ,
300
+ port: nil ,
301
+ path: "/path/info" ,
302
+ query: nil ,
303
+ fragment: nil
304
+ }
305
+ end
294
306
end
295
307
296
308
test "http://http://http://@http://http://?http://#http://" do
You can’t perform that action at this time.
0 commit comments