From 92ce2ff28966fb3216e3af1f77bc66494937057a Mon Sep 17 00:00:00 2001 From: pnezis Date: Wed, 11 Mar 2026 09:38:49 +0200 Subject: [PATCH] Fix `URI.merge` leaking `:+` marker when base path is empty string 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. --- lib/elixir/lib/uri.ex | 1 + lib/elixir/test/elixir/uri_test.exs | 6 ++++++ 2 files changed, 7 insertions(+) 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