Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e588271

Browse files
hsbtnagachika
authored andcommitted
Merge uri-0.13.2
1 parent 188ff4d commit e588271

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
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

lib/uri/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module URI
22
# :stopdoc:
3-
VERSION_CODE = '001301'.freeze
3+
VERSION_CODE = '001302'.freeze
44
VERSION = VERSION_CODE.scan(/../).collect{|n| n.to_i}.join('.').freeze
55
# :startdoc:
66
end

test/uri/test_generic.rb

+18
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,17 @@ def test_parse
164164
# must be empty string to identify as path-abempty, not path-absolute
165165
assert_equal('', url.host)
166166
assert_equal('http:////example.com', url.to_s)
167+
168+
# sec-2957667
169+
url = URI.parse('http://user:[email protected]').merge('//example.net')
170+
assert_equal('http://example.net', url.to_s)
171+
assert_nil(url.userinfo)
172+
url = URI.join('http://user:[email protected]', '//example.net')
173+
assert_equal('http://example.net', url.to_s)
174+
assert_nil(url.userinfo)
175+
url = URI.parse('http://user:[email protected]') + '//example.net'
176+
assert_equal('http://example.net', url.to_s)
177+
assert_nil(url.userinfo)
167178
end
168179

169180
def test_parse_scheme_with_symbols
@@ -256,6 +267,13 @@ def test_merge
256267
assert_equal(u0, u1)
257268
end
258269

270+
def test_merge_authority
271+
u = URI.parse('http://user:[email protected]:8080')
272+
u0 = URI.parse('http://new.example.org/path')
273+
u1 = u.merge('//new.example.org/path')
274+
assert_equal(u0, u1)
275+
end
276+
259277
def test_route
260278
url = URI.parse('http://hoge/a.html').route_to('http://hoge/b.html')
261279
assert_equal('b.html', url.to_s)

0 commit comments

Comments
 (0)