Skip to content

Commit 5a3fa52

Browse files
authored
Merge pull request #154 from ruby/remove-userinfo
Remove userinfo
2 parents f198601 + 2789182 commit 5a3fa52

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

lib/uri/generic.rb

+7-8
Original file line numberDiff line numberDiff line change
@@ -1133,17 +1133,16 @@ def merge(oth)
11331133
base.fragment=(nil)
11341134

11351135
# RFC2396, Section 5.2, 4)
1136-
if !authority
1137-
base.set_path(merge_path(base.path, rel.path)) if base.path && rel.path
1138-
else
1139-
# RFC2396, Section 5.2, 4)
1140-
base.set_path(rel.path) if rel.path
1136+
if authority
1137+
base.set_userinfo(rel.userinfo)
1138+
base.set_host(rel.host)
1139+
base.set_port(rel.port || base.default_port)
1140+
base.set_path(rel.path)
1141+
elsif base.path && rel.path
1142+
base.set_path(merge_path(base.path, rel.path))
11411143
end
11421144

11431145
# RFC2396, Section 5.2, 7)
1144-
base.set_userinfo(rel.userinfo) if rel.userinfo
1145-
base.set_host(rel.host) if rel.host
1146-
base.set_port(rel.port) if rel.port
11471146
base.query = rel.query if rel.query
11481147
base.fragment=(rel.fragment) if rel.fragment
11491148

test/uri/test_generic.rb

+18
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
@@ -267,6 +278,13 @@ def test_merge
267278
assert_equal(u0, u1)
268279
end
269280

281+
def test_merge_authority
282+
u = URI.parse('http://user:[email protected]:8080')
283+
u0 = URI.parse('http://new.example.org/path')
284+
u1 = u.merge('//new.example.org/path')
285+
assert_equal(u0, u1)
286+
end
287+
270288
def test_route
271289
url = URI.parse('http://hoge/a.html').route_to('http://hoge/b.html')
272290
assert_equal('b.html', url.to_s)

0 commit comments

Comments
 (0)