Skip to content

Commit 6c6449e

Browse files
nobuhsbt
authored andcommitted
Add authority accessor
1 parent 5cec76b commit 6c6449e

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

lib/uri/generic.rb

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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
#
@@ -1123,7 +1136,7 @@ def merge(oth)
11231136

11241137
base = self.dup
11251138

1126-
authority = rel.userinfo || rel.host || rel.port
1139+
authority = rel.authority
11271140

11281141
# RFC2396, Section 5.2, 2)
11291142
if (rel.path.nil? || rel.path.empty?) && !authority && !rel.query
@@ -1136,9 +1149,7 @@ def merge(oth)
11361149

11371150
# RFC2396, Section 5.2, 4)
11381151
if authority
1139-
base.set_userinfo(rel.userinfo)
1140-
base.set_host(rel.host)
1141-
base.set_port(rel.port || base.default_port)
1152+
base.set_authority(*authority)
11421153
base.set_path(rel.path)
11431154
elsif base.path && rel.path
11441155
base.set_path(merge_path(base.path, rel.path))

0 commit comments

Comments
 (0)