Skip to content

Commit 3675494

Browse files
committed
Truncate userinfo with URI#join, URI#merge and URI#+
1 parent f198601 commit 3675494

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/uri/generic.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,11 @@ def merge(oth)
11411141
end
11421142

11431143
# RFC2396, Section 5.2, 7)
1144-
base.set_userinfo(rel.userinfo) if rel.userinfo
1144+
if rel.userinfo
1145+
base.set_userinfo(rel.userinfo)
1146+
else
1147+
base.set_userinfo(nil)
1148+
end
11451149
base.set_host(rel.host) if rel.host
11461150
base.set_port(rel.port) if rel.port
11471151
base.query = rel.query if rel.query

test/uri/test_generic.rb

+11
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,17 @@ def test_parse
175175
# must be empty string to identify as path-abempty, not path-absolute
176176
assert_equal('', url.host)
177177
assert_equal('http:////example.com', url.to_s)
178+
179+
# sec-2957667
180+
url = URI.parse('http://user:[email protected]').merge('//example.net')
181+
assert_equal('http://example.net', url.to_s)
182+
assert_nil(url.userinfo)
183+
url = URI.join('http://user:[email protected]', '//example.net')
184+
assert_equal('http://example.net', url.to_s)
185+
assert_nil(url.userinfo)
186+
url = URI.parse('http://user:[email protected]') + '//example.net'
187+
assert_equal('http://example.net', url.to_s)
188+
assert_nil(url.userinfo)
178189
end
179190

180191
def test_parse_scheme_with_symbols

0 commit comments

Comments
 (0)