diff options
| author | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2025-10-07 18:27:27 +0900 |
|---|---|---|
| committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2025-10-07 19:54:25 +0900 |
| commit | 2c01a34978b104113025d45d85eb30c1dbbea0cb (patch) | |
| tree | fa2d066c555955bb803d84861631ba173f1dfc8c | |
| parent | 94aabd3415e3251e9058089d85dfeef30c3f2dfc (diff) | |
Merge URI-0.12.5
| -rw-r--r-- | lib/uri/generic.rb | 29 | ||||
| -rw-r--r-- | lib/uri/version.rb | 2 | ||||
| -rw-r--r-- | test/uri/test_generic.rb | 15 |
3 files changed, 32 insertions, 14 deletions
diff --git a/lib/uri/generic.rb b/lib/uri/generic.rb index f7eed57924..31dfac8c26 100644 --- a/lib/uri/generic.rb +++ b/lib/uri/generic.rb @@ -186,18 +186,18 @@ module URI if arg_check self.scheme = scheme - self.userinfo = userinfo self.hostname = host self.port = port + self.userinfo = userinfo self.path = path self.query = query self.opaque = opaque self.fragment = fragment else self.set_scheme(scheme) - self.set_userinfo(userinfo) self.set_host(host) self.set_port(port) + self.set_userinfo(userinfo) self.set_path(path) self.query = query self.set_opaque(opaque) @@ -511,7 +511,7 @@ module URI user, password = split_userinfo(user) end @user = user - @password = password if password + @password = password [@user, @password] end @@ -522,7 +522,7 @@ module URI # See also URI::Generic.user=. # def set_user(v) - set_userinfo(v, @password) + set_userinfo(v, nil) v end protected :set_user @@ -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 # @@ -639,6 +652,7 @@ module URI def host=(v) check_host(v) set_host(v) + set_userinfo(nil) v end @@ -729,6 +743,7 @@ module URI def port=(v) check_port(v) set_port(v) + set_userinfo(nil) port end @@ -1121,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 @@ -1134,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)) diff --git a/lib/uri/version.rb b/lib/uri/version.rb index c93c97cf6f..7f7c272365 100644 --- a/lib/uri/version.rb +++ b/lib/uri/version.rb @@ -1,6 +1,6 @@ module URI # :stopdoc: - VERSION_CODE = '001204'.freeze + VERSION_CODE = '001205'.freeze VERSION = VERSION_CODE.scan(/../).collect{|n| n.to_i}.join('.').freeze # :startdoc: end diff --git a/test/uri/test_generic.rb b/test/uri/test_generic.rb index 4b5e12c0ef..d54554f28c 100644 --- a/test/uri/test_generic.rb +++ b/test/uri/test_generic.rb @@ -272,6 +272,9 @@ class URI::TestGeneric < Test::Unit::TestCase u0 = URI.parse('http://new.example.org/path') u1 = u.merge('//new.example.org/path') assert_equal(u0, u1) + u0 = URI.parse('http://other@example.net') + u1 = u.merge('//other@example.net') + assert_equal(u0, u1) end def test_route @@ -737,17 +740,18 @@ class URI::TestGeneric < Test::Unit::TestCase def test_set_component uri = URI.parse('http://foo:bar@baz') assert_equal('oof', uri.user = 'oof') - assert_equal('http://oof:bar@baz', uri.to_s) + assert_equal('http://oof@baz', uri.to_s) assert_equal('rab', uri.password = 'rab') assert_equal('http://oof:rab@baz', uri.to_s) assert_equal('foo', uri.userinfo = 'foo') - assert_equal('http://foo:rab@baz', uri.to_s) + assert_equal('http://foo@baz', uri.to_s) assert_equal(['foo', 'bar'], uri.userinfo = ['foo', 'bar']) assert_equal('http://foo:bar@baz', uri.to_s) assert_equal(['foo'], uri.userinfo = ['foo']) - assert_equal('http://foo:bar@baz', uri.to_s) + assert_equal('http://foo@baz', uri.to_s) assert_equal('zab', uri.host = 'zab') - assert_equal('http://foo:bar@zab', uri.to_s) + assert_equal('http://zab', uri.to_s) + uri.userinfo = ['foo', 'bar'] uri.port = "" assert_nil(uri.port) uri.port = "80" @@ -757,7 +761,8 @@ class URI::TestGeneric < Test::Unit::TestCase uri.port = " 080 " assert_equal(80, uri.port) assert_equal(8080, uri.port = 8080) - assert_equal('http://foo:bar@zab:8080', uri.to_s) + assert_equal('http://zab:8080', uri.to_s) + uri = URI.parse('http://foo:bar@zab:8080') assert_equal('/', uri.path = '/') assert_equal('http://foo:bar@zab:8080/', uri.to_s) assert_equal('a=1', uri.query = 'a=1') |
