diff --git a/lib/elixir/lib/uri.ex b/lib/elixir/lib/uri.ex index 4c474f1cab4..3f6fd7e1f44 100644 --- a/lib/elixir/lib/uri.ex +++ b/lib/elixir/lib/uri.ex @@ -964,6 +964,7 @@ defmodule URI do end defp merge_paths(nil, rel_path), do: merge_paths("/", rel_path) + defp merge_paths("", rel_path), do: merge_paths("/", rel_path) defp merge_paths(_, "/" <> _ = rel_path), do: remove_dot_segments_from_path(rel_path) defp merge_paths(base_path, rel_path) do diff --git a/lib/elixir/test/elixir/uri_test.exs b/lib/elixir/test/elixir/uri_test.exs index 598d0af870c..0c58db61efd 100644 --- a/lib/elixir/test/elixir/uri_test.exs +++ b/lib/elixir/test/elixir/uri_test.exs @@ -1044,5 +1044,11 @@ defmodule URITest do assert URI.merge(base, "/foo") |> to_string() == "http://example.com/foo" assert URI.merge(base, "foo") |> to_string() == "http://example.com/foo" end + + test "merges when base path is empty string" do + base = %URI{scheme: "http", host: "example.com", path: ""} + assert URI.merge(base, "foo") |> to_string() == "http://example.com/foo" + assert URI.merge(base, "/bar") |> to_string() == "http://example.com/bar" + end end end