Skip to content

Commit

Permalink
Truncate userinfo with URI#join, URI#merge and URI#+
Browse files Browse the repository at this point in the history
  • Loading branch information
hsbt committed Feb 26, 2025
1 parent f198601 commit 3675494
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/uri/generic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,11 @@ def merge(oth)
end

# RFC2396, Section 5.2, 7)
base.set_userinfo(rel.userinfo) if rel.userinfo
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
Expand Down
11 changes: 11 additions & 0 deletions test/uri/test_generic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,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

0 comments on commit 3675494

Please sign in to comment.