From c36a0f0ec0a77c47f5378118913250ea983266c2 Mon Sep 17 00:00:00 2001 From: akira Date: Wed, 23 Feb 2005 06:08:29 +0000 Subject: * lib/uri/generic.rb (split_userinfo): should split ":pass" into "" and "pass". [ruby-dev:25667] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8020 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ lib/uri/generic.rb | 9 +-------- test/uri/test_generic.rb | 17 ++++++++++++++++- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index b721da7b21..12a86948a3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Feb 23 15:04:32 2005 akira yamada + + * lib/uri/generic.rb (split_userinfo): should split ":pass" into "" + and "pass". [ruby-dev:25667] + Wed Feb 23 01:53:29 2005 Shugo Maeda * lib/net/imap.rb (initialize): handle certs correctly. Thanks, diff --git a/lib/uri/generic.rb b/lib/uri/generic.rb index 0dedcf494a..3253450046 100644 --- a/lib/uri/generic.rb +++ b/lib/uri/generic.rb @@ -343,14 +343,7 @@ module URI def split_userinfo(ui) return nil, nil unless ui - tmp = ui.index(':') - if tmp - user = ui[0..tmp - 1] - password = ui[tmp + 1..-1] - else - user = ui - password = nil - end + user, password = ui.split(/:/, 2) return user, password end diff --git a/test/uri/test_generic.rb b/test/uri/test_generic.rb index 8740574e4e..8a7feb4982 100644 --- a/test/uri/test_generic.rb +++ b/test/uri/test_generic.rb @@ -117,11 +117,26 @@ class TestGeneric < Test::Unit::TestCase assert_raises(URI::InvalidURIError) { URI.parse('http://a_b/') } # 8 - # reporte by m_seki + # reported by m_seki uri = URI.parse('file:///foo/bar.txt') assert_kind_of(URI::Generic, url) uri = URI.parse('file:/foo/bar.txt') assert_kind_of(URI::Generic, url) + + # 9 + # [ruby-dev:25667] + url = URI.parse('ftp://:pass@localhost/') + assert_equal('', url.user) + assert_equal('pass', url.password) + assert_equal(':pass', url.userinfo) + url = URI.parse('ftp://user@localhost/') + assert_equal('user', url.user) + assert_equal(nil, url.password) + assert_equal('user', url.userinfo) + url = URI.parse('ftp://localhost/') + assert_equal(nil, url.user) + assert_equal(nil, url.password) + assert_equal(nil, url.userinfo) end def test_merge -- cgit v1.2.3