Skip to content
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

Fix bug with schemaless URI in URI.merge/2 #13970

Merged
merged 1 commit into from
Nov 6, 2024

Conversation

PragTob
Copy link
Contributor

@PragTob PragTob commented Nov 6, 2024

Only occurs when mixing strings and URIs, but the docs seem to encourage that.

Without the fix the test results in the following error:

  1) test merge/2 (URITest)
     test/elixir/uri_test.exs:376
     ** (KeyError) key :scheme not found in: "http://google.com/foo"

     If you are using the dot syntax, such as map.field, make sure the left-hand side of the dot is a map
     code: assert URI.merge("http://google.com/foo", URI.new!("//example.com/baz"))
     stacktrace:
       (elixir 1.18.0-dev) lib/uri.ex:911: URI.merge/2
       test/elixir/uri_test.exs:390: (test)

That's because that (one) particular clause didn't check for the base to be a %URI{}.

Happy to also backport it to the 1.17 branch (should be easy/ probably cherry-pickable) but:

  1. seems like an extreme edge case
  2. a workaround is available (use URI/URI or String/String as args)

Thank you all for your excellent work! 💚 🚀

Only occurs when mixing strings and URIs, but the docs seem to
encourage that.

Without the fix the test results in the following error:

```
  1) test merge/2 (URITest)
     test/elixir/uri_test.exs:376
     ** (KeyError) key :scheme not found in: "http://google.com/foo"

     If you are using the dot syntax, such as map.field, make sure the left-hand side of the dot is a map
     code: assert URI.merge("http://google.com/foo", URI.new!("//example.com/baz"))
     stacktrace:
       (elixir 1.18.0-dev) lib/uri.ex:911: URI.merge/2
       test/elixir/uri_test.exs:390: (test)
```

That's because that (one) particular clause didn't check for the
base to be a `%URI{}`.

Happy to also backport it to the 1.17 branch (should be easy/
probably cherry-pickable) but:
1. seems like an extreme edge case
2. a workaround is available (use URI/URI or String/String as args)
@josevalim josevalim merged commit e28a84c into elixir-lang:main Nov 6, 2024
9 checks passed
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

@PragTob PragTob deleted the uri-merge-edge-case-fix branch November 6, 2024 12:37
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