Skip to content

Commit 3baf987

Browse files
authored
Fix URI.merge/2 for hostless absolute base URIs (#14344)
1 parent d83f961 commit 3baf987

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/elixir/lib/uri.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ defmodule URI do
903903
@spec merge(t | binary, t | binary) :: t
904904
def merge(uri, rel)
905905

906-
def merge(%URI{host: nil}, _rel) do
906+
def merge(%URI{scheme: nil}, _rel) do
907907
raise ArgumentError, "you must merge onto an absolute URI"
908908
end
909909

lib/elixir/test/elixir/uri_test.exs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,11 @@ defmodule URITest do
460460
"https://images.example.com/t/1600x/https://images.example.com/foo.jpg"
461461
end
462462

463+
test "merge/2 with host-less URIs" do
464+
assert URI.merge("tag:example", "foo") |> to_string == "tag:foo"
465+
assert URI.merge("tag:example", "#fragment") |> to_string == "tag:example#fragment"
466+
end
467+
463468
test "merge/2 (with RFC examples)" do
464469
# These are examples from:
465470
#

0 commit comments

Comments
 (0)