Skip to content

Commit e28a84c

Browse files
authored
Fix bug with schemaless URI in URI.merge/2 (#13970)
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{}`.
1 parent 75fd563 commit e28a84c

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

lib/elixir/lib/uri.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ defmodule URI do
907907
%{rel | path: remove_dot_segments_from_path(rel.path)}
908908
end
909909

910-
def merge(base, %URI{host: host} = rel) when host != nil do
910+
def merge(%URI{} = base, %URI{host: host} = rel) when host != nil do
911911
%{rel | scheme: base.scheme, path: remove_dot_segments_from_path(rel.path)}
912912
end
913913

lib/elixir/test/elixir/uri_test.exs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,9 @@ defmodule URITest do
387387
assert URI.merge("http://google.com/foo", "//example.com/baz")
388388
|> to_string == "http://example.com/baz"
389389

390+
assert URI.merge("http://google.com/foo", URI.new!("//example.com/baz"))
391+
|> to_string == "http://example.com/baz"
392+
390393
assert URI.merge("http://google.com/foo", "//example.com/.././bar/../../../baz")
391394
|> to_string == "http://example.com/baz"
392395

0 commit comments

Comments
 (0)