Skip to content

Conversation

@marcelotto
Copy link
Contributor

Here's another fix for a URI.merge/2 issue that was uncovered by the W3C JSON-LD 1.1 Test suite.

The current implementation incorrectly rejects base URIs with a scheme but without a host:

iex> URI.merge("tag:example", "foo")
** (ArgumentError) you must merge onto an absolute URI
    (elixir 1.18.2) lib/uri.ex:903: URI.merge/2


def merge(%URI{host: nil}, _rel) do
def merge(%URI{scheme: nil}, _rel) do
raise ArgumentError, "you must merge onto an absolute URI"
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure if this message is correct. Also, shouldn't be fine to merge into //foo/bar? Should we add a test for that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Regarding the error message: I believe the message has become more accurate with this change. But "base must be an absolute URI" might be clearer.

Regarding //foo/bar: Such a network-path reference, is still a relative URI and should IMO lead to this error when used as a base.

@josevalim josevalim merged commit 3baf987 into elixir-lang:main Mar 18, 2025
10 checks passed
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

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.

2 participants