Skip to content

Commit

Permalink
Merge pull request #155 from ruby/remove-userinfo-v0-13
Browse files Browse the repository at this point in the history
Remove userinfo for v0.13.x
  • Loading branch information
hsbt authored Feb 26, 2025
2 parents 56490e4 + 75aeb4a commit 07fe169
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
15 changes: 7 additions & 8 deletions lib/uri/generic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1133,17 +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)
base.set_userinfo(rel.userinfo) if rel.userinfo
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
18 changes: 18 additions & 0 deletions test/uri/test_generic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,17 @@ def test_parse
# must be empty string to identify as path-abempty, not path-absolute
assert_equal('', url.host)
assert_equal('http:////example.com', url.to_s)

# sec-2957667
url = URI.parse('http://user:[email protected]').merge('//example.net')
assert_equal('http://example.net', url.to_s)
assert_nil(url.userinfo)
url = URI.join('http://user:[email protected]', '//example.net')
assert_equal('http://example.net', url.to_s)
assert_nil(url.userinfo)
url = URI.parse('http://user:[email protected]') + '//example.net'
assert_equal('http://example.net', url.to_s)
assert_nil(url.userinfo)
end

def test_parse_scheme_with_symbols
Expand Down Expand Up @@ -256,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 07fe169

Please sign in to comment.