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

Conversation

tfiedlerdejanze
Copy link
Contributor

Resolves #13462

When a url string is schema less and the host is followed by a colon without setting the actual port, :uri_string.parse/1 returns the port to be :undefined. As long as the url string is parseable, we should translate :undefiend to nil, in order to ensure we return a valid URI struct.

Resolves elixir-lang#13462

When a url string is schema less and the host is followed by a colon
without setting the actual port, `:uri_string.parse/1` returns the
port to be `:undefined`. As long as the url string is parseable,
we should translate `:undefiend` to `nil`, in order to ensure we return a valid URI struct.
@@ -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

@josevalim josevalim merged commit 53bf241 into elixir-lang:main Apr 2, 2024
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

josevalim pushed a commit that referenced this pull request Apr 4, 2024
Resolves #13462

When a url string is schema less and the host is followed by a colon
without setting the actual port, `:uri_string.parse/1` returns the
port to be `:undefined`. As long as the url string is parseable,
we should translate `:undefined` to `nil`, in order to ensure we return
a valid URI struct.
josevalim pushed a commit that referenced this pull request May 6, 2024
Resolves #13462

When a url string is schema less and the host is followed by a colon
without setting the actual port, `:uri_string.parse/1` returns the
port to be `:undefined`. As long as the url string is parseable,
we should translate `:undefined` to `nil`, in order to ensure we return
a valid URI struct.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

URI.to_string causes ArgumentError when :port is :undefined
3 participants