Skip to content

Translate :undefined URI port to nil #13464

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/elixir/lib/uri.ex
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,9 @@ defmodule URI do
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the branch line 664 could also lead to an :undefined port?

Copy link
Contributor Author

@tfiedlerdejanze tfiedlerdejanze Apr 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely right! I was able to reproduce using a scheme which has no port mapped through default_port/1 and added a test for it in ed85d09

end

%{port: :undefined} ->
%{uri | port: nil}

%{} ->
uri
end
Expand Down
14 changes: 14 additions & 0 deletions lib/elixir/test/elixir/uri_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,20 @@ defmodule URITest do
assert URI.new("") == {:ok, %URI{}}
end

test "missing port part after host never resolves to :undefined" do
assert URI.new("//https://www.example.com") ==
{:ok,
%URI{
scheme: nil,
userinfo: nil,
host: "https",
port: nil,
path: "//www.example.com",
query: nil,
fragment: nil
}}
end

test "errors on bad URIs" do
assert URI.new("/>") == {:error, ">"}
assert URI.new(":https") == {:error, ":"}
Expand Down