Skip to content

Commit ababaf8

Browse files
authored
Fix URI.merge leaking :+ marker when base path is empty string (#15179)
When merging URIs where the base has `path: ""`, the internal `:+` marker used to track the join point between base and relative paths was being converted to a literal "+" in the output.
1 parent a064a00 commit ababaf8

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

lib/elixir/lib/uri.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,7 @@ defmodule URI do
964964
end
965965

966966
defp merge_paths(nil, rel_path), do: merge_paths("/", rel_path)
967+
defp merge_paths("", rel_path), do: merge_paths("/", rel_path)
967968
defp merge_paths(_, "/" <> _ = rel_path), do: remove_dot_segments_from_path(rel_path)
968969

969970
defp merge_paths(base_path, rel_path) do

lib/elixir/test/elixir/uri_test.exs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,5 +1044,11 @@ defmodule URITest do
10441044
assert URI.merge(base, "/foo") |> to_string() == "http://example.com/foo"
10451045
assert URI.merge(base, "foo") |> to_string() == "http://example.com/foo"
10461046
end
1047+
1048+
test "merges when base path is empty string" do
1049+
base = %URI{scheme: "http", host: "example.com", path: ""}
1050+
assert URI.merge(base, "foo") |> to_string() == "http://example.com/foo"
1051+
assert URI.merge(base, "/bar") |> to_string() == "http://example.com/bar"
1052+
end
10471053
end
10481054
end

0 commit comments

Comments
 (0)