summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2025-06-26 01:21:50 +0900
committergit <svn-admin@ruby-lang.org>2025-10-07 01:12:42 +0000
commiteccc54b4fa437f896cde1bdee7f855b6e541cb82 (patch)
tree676b3deee9f38ad24f3ad6007bd69ea19d68401e
parentd0395bd0ead968e194e268f8c5f9db59d8831c02 (diff)
[ruby/uri] Add authority accessor
https://github.com/ruby/uri/commit/6c6449e15f
-rw-r--r--lib/uri/generic.rb19
1 files changed, 15 insertions, 4 deletions
diff --git a/lib/uri/generic.rb b/lib/uri/generic.rb
index abdf5b4377..634da49fe9 100644
--- a/lib/uri/generic.rb
+++ b/lib/uri/generic.rb
@@ -574,6 +574,12 @@ module URI
@password
end
+ # Returns the authority info (array of user, password, host and
+ # port), if any is set. Or returns +nil+.
+ def authority
+ return @user, @password, @host, @port if @user || @password || @host || @port
+ end
+
# Returns the user component after URI decoding.
def decoded_user
URI.decode_uri_component(@user) if @user
@@ -615,6 +621,13 @@ module URI
end
protected :set_host
+ # Protected setter for the authority info (+user+, +password+, +host+
+ # and +port+). If +port+ is +nil+, +default_port+ will be set.
+ #
+ protected def set_authority(user, password, host, port = nil)
+ @user, @password, @host, @port = user, password, host, port || self.default_port
+ end
+
#
# == Args
#
@@ -1123,7 +1136,7 @@ module URI
base = self.dup
- authority = rel.userinfo || rel.host || rel.port
+ authority = rel.authority
# RFC2396, Section 5.2, 2)
if (rel.path.nil? || rel.path.empty?) && !authority && !rel.query
@@ -1136,9 +1149,7 @@ module URI
# RFC2396, Section 5.2, 4)
if authority
- base.set_userinfo(rel.userinfo)
- base.set_host(rel.host)
- base.set_port(rel.port || base.default_port)
+ base.set_authority(*authority)
base.set_path(rel.path)
elsif base.path && rel.path
base.set_path(merge_path(base.path, rel.path))