[ruby/uri] Truncate userinfo with URI#join, URI#merge and URI#+

https://github.com/ruby/uri/commit/3675494839
This commit is contained in:
Hiroshi SHIBATA 2025-02-21 16:29:36 +09:00 committed by git
parent 7d24e1d655
commit 57dcb4bb9b
2 changed files with 16 additions and 1 deletions

View File

@ -1141,7 +1141,11 @@ module URI
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

View File

@ -175,6 +175,17 @@ class URI::TestGeneric < Test::Unit::TestCase
# 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:pass@example.com').merge('//example.net')
assert_equal('http://example.net', url.to_s)
assert_nil(url.userinfo)
url = URI.join('http://user:pass@example.com', '//example.net')
assert_equal('http://example.net', url.to_s)
assert_nil(url.userinfo)
url = URI.parse('http://user:pass@example.com') + '//example.net'
assert_equal('http://example.net', url.to_s)
assert_nil(url.userinfo)
end
def test_parse_scheme_with_symbols