Skip to content

Commit

Permalink
Fix merger of URI with authority component
Browse files Browse the repository at this point in the history
  • Loading branch information
hsbt and nobu committed Feb 26, 2025
1 parent cc7d2c7 commit 75aeb4a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
19 changes: 7 additions & 12 deletions lib/uri/generic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1133,21 +1133,16 @@ def merge(oth)
base.fragment=(nil)

# RFC2396, Section 5.2, 4)
if !authority
base.set_path(merge_path(base.path, rel.path)) if base.path && rel.path
else
# RFC2396, Section 5.2, 4)
base.set_path(rel.path) if rel.path
if authority
base.set_userinfo(rel.userinfo)
base.set_host(rel.host)
base.set_port(rel.port || base.default_port)
base.set_path(rel.path)
elsif base.path && rel.path
base.set_path(merge_path(base.path, rel.path))
end

# RFC2396, Section 5.2, 7)
if rel.userinfo
base.set_userinfo(rel.userinfo)
else
base.set_userinfo(nil)
end
base.set_host(rel.host) if rel.host
base.set_port(rel.port) if rel.port
base.query = rel.query if rel.query
base.fragment=(rel.fragment) if rel.fragment

Expand Down
7 changes: 7 additions & 0 deletions test/uri/test_generic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,13 @@ def test_merge
assert_equal(u0, u1)
end

def test_merge_authority
u = URI.parse('http://user:[email protected]:8080')
u0 = URI.parse('http://new.example.org/path')
u1 = u.merge('//new.example.org/path')
assert_equal(u0, u1)
end

def test_route
url = URI.parse('http://hoge/a.html').route_to('http://hoge/b.html')
assert_equal('b.html', url.to_s)
Expand Down

0 comments on commit 75aeb4a

Please sign in to comment.