Skip to content

Commit 52077e9

Browse files
committed
Merge tag 'v1.0.4'
2 parents 704d9fe + e507473 commit 52077e9

File tree

3 files changed

+32
-14
lines changed

3 files changed

+32
-14
lines changed

lib/uri/generic.rb

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,18 +186,18 @@ def initialize(scheme,
186186

187187
if arg_check
188188
self.scheme = scheme
189-
self.userinfo = userinfo
190189
self.hostname = host
191190
self.port = port
191+
self.userinfo = userinfo
192192
self.path = path
193193
self.query = query
194194
self.opaque = opaque
195195
self.fragment = fragment
196196
else
197197
self.set_scheme(scheme)
198-
self.set_userinfo(userinfo)
199198
self.set_host(host)
200199
self.set_port(port)
200+
self.set_userinfo(userinfo)
201201
self.set_path(path)
202202
self.query = query
203203
self.set_opaque(opaque)
@@ -511,7 +511,7 @@ def set_userinfo(user, password = nil)
511511
user, password = split_userinfo(user)
512512
end
513513
@user = user
514-
@password = password if password
514+
@password = password
515515

516516
[@user, @password]
517517
end
@@ -522,7 +522,7 @@ def set_userinfo(user, password = nil)
522522
# See also URI::Generic.user=.
523523
#
524524
def set_user(v)
525-
set_userinfo(v, @password)
525+
set_userinfo(v, nil)
526526
v
527527
end
528528
protected :set_user
@@ -574,6 +574,12 @@ def password
574574
@password
575575
end
576576

577+
# Returns the authority info (array of user, password, host and
578+
# port), if any is set. Or returns +nil+.
579+
def authority
580+
return @user, @password, @host, @port if @user || @password || @host || @port
581+
end
582+
577583
# Returns the user component after URI decoding.
578584
def decoded_user
579585
URI.decode_uri_component(@user) if @user
@@ -615,6 +621,13 @@ def set_host(v)
615621
end
616622
protected :set_host
617623

624+
# Protected setter for the authority info (+user+, +password+, +host+
625+
# and +port+). If +port+ is +nil+, +default_port+ will be set.
626+
#
627+
protected def set_authority(user, password, host, port = nil)
628+
@user, @password, @host, @port = user, password, host, port || self.default_port
629+
end
630+
618631
#
619632
# == Args
620633
#
@@ -639,6 +652,7 @@ def set_host(v)
639652
def host=(v)
640653
check_host(v)
641654
set_host(v)
655+
set_userinfo(nil)
642656
v
643657
end
644658

@@ -729,6 +743,7 @@ def set_port(v)
729743
def port=(v)
730744
check_port(v)
731745
set_port(v)
746+
set_userinfo(nil)
732747
port
733748
end
734749

@@ -1121,7 +1136,7 @@ def merge(oth)
11211136

11221137
base = self.dup
11231138

1124-
authority = rel.userinfo || rel.host || rel.port
1139+
authority = rel.authority
11251140

11261141
# RFC2396, Section 5.2, 2)
11271142
if (rel.path.nil? || rel.path.empty?) && !authority && !rel.query
@@ -1134,9 +1149,7 @@ def merge(oth)
11341149

11351150
# RFC2396, Section 5.2, 4)
11361151
if authority
1137-
base.set_userinfo(rel.userinfo)
1138-
base.set_host(rel.host)
1139-
base.set_port(rel.port || base.default_port)
1152+
base.set_authority(*authority)
11401153
base.set_path(rel.path)
11411154
elsif base.path && rel.path
11421155
base.set_path(merge_path(base.path, rel.path))

lib/uri/version.rb

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

test/uri/test_generic.rb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,9 @@ def test_merge_authority
283283
u0 = URI.parse('http://new.example.org/path')
284284
u1 = u.merge('//new.example.org/path')
285285
assert_equal(u0, u1)
286+
u0 = URI.parse('http://[email protected]')
287+
u1 = u.merge('//[email protected]')
288+
assert_equal(u0, u1)
286289
end
287290

288291
def test_route
@@ -748,17 +751,18 @@ def test_join
748751
def test_set_component
749752
uri = URI.parse('http://foo:bar@baz')
750753
assert_equal('oof', uri.user = 'oof')
751-
assert_equal('http://oof:bar@baz', uri.to_s)
754+
assert_equal('http://oof@baz', uri.to_s)
752755
assert_equal('rab', uri.password = 'rab')
753756
assert_equal('http://oof:rab@baz', uri.to_s)
754757
assert_equal('foo', uri.userinfo = 'foo')
755-
assert_equal('http://foo:rab@baz', uri.to_s)
758+
assert_equal('http://foo@baz', uri.to_s)
756759
assert_equal(['foo', 'bar'], uri.userinfo = ['foo', 'bar'])
757760
assert_equal('http://foo:bar@baz', uri.to_s)
758761
assert_equal(['foo'], uri.userinfo = ['foo'])
759-
assert_equal('http://foo:bar@baz', uri.to_s)
762+
assert_equal('http://foo@baz', uri.to_s)
760763
assert_equal('zab', uri.host = 'zab')
761-
assert_equal('http://foo:bar@zab', uri.to_s)
764+
assert_equal('http://zab', uri.to_s)
765+
uri.userinfo = ['foo', 'bar']
762766
uri.port = ""
763767
assert_nil(uri.port)
764768
uri.port = "80"
@@ -768,7 +772,8 @@ def test_set_component
768772
uri.port = " 080 "
769773
assert_equal(80, uri.port)
770774
assert_equal(8080, uri.port = 8080)
771-
assert_equal('http://foo:bar@zab:8080', uri.to_s)
775+
assert_equal('http://zab:8080', uri.to_s)
776+
uri = URI.parse('http://foo:bar@zab:8080')
772777
assert_equal('/', uri.path = '/')
773778
assert_equal('http://foo:bar@zab:8080/', uri.to_s)
774779
assert_equal('a=1', uri.query = 'a=1')

0 commit comments

Comments
 (0)