* lib/uri/generic.rb (URI::Generic::check_userinfo,

URI::Generic::check_user, URI::Generic::check_password): tests
  conflicts/depends with other components closely.

* test/uri/test_generic.rb (TestGeneric::test_set_component):
  added tets.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5256 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akira 2003-12-23 05:17:00 +00:00
Родитель 53ebcbf733
Коммит 4bb0fd231e
3 изменённых файлов: 37 добавлений и 9 удалений

Просмотреть файл

@ -1,3 +1,12 @@
Tue Dec 23 14:13:51 2003 akira yamada <akira@ruby-lang.org>
* lib/uri/generic.rb (URI::Generic::check_userinfo,
URI::Generic::check_user, URI::Generic::check_password): tests
conflicts/depends with other components closely.
* test/uri/test_generic.rb (TestGeneric::test_set_component):
added tets.
Tue Dec 23 11:08:34 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
* test/xsd/test_noencoding.rb: rescue Errno::EINVAL and do not test.

Просмотреть файл

@ -265,23 +265,22 @@ Object
# methods for userinfo
#
def check_userinfo(user, password = nil)
if (user || password) &&
(@registry || @opaque)
raise InvalidURIError,
"can not set userinfo with registry or opaque"
end
if !password
user, password = split_userinfo(user)
end
check_user(user)
check_password(password)
check_password(password, user)
return true
end
private :check_userinfo
def check_user(v)
if @registry || @opaque
raise InvalidURIError,
"can not set user with registry or opaque"
end
return v unless v
if USERINFO !~ v
@ -293,10 +292,14 @@ Object
end
private :check_user
def check_password(v)
def check_password(v, user = @user)
if @registry || @opaque
raise InvalidURIError,
"can not set password with registry or opaque"
end
return v unless v
if !@password
if !user
raise InvalidURIError,
"password component depends user component"
end

Просмотреть файл

@ -619,6 +619,22 @@ class TestGeneric < Test::Unit::TestCase
assert_equal('http://foo:bar@zab:8080/?a=1', uri.to_s)
assert_equal('b123', uri.fragment = 'b123')
assert_equal('http://foo:bar@zab:8080/?a=1#b123', uri.to_s)
uri = URI.parse('http://example.com')
assert_raises(URI::InvalidURIError) { uri.password = 'bar' }
uri.userinfo = 'foo:bar'
assert_equal('http://foo:bar@example.com', uri.to_s)
assert_raises(URI::InvalidURIError) { uri.registry = 'bar' }
assert_raises(URI::InvalidURIError) { uri.opaque = 'bar' }
uri = URI.parse('mailto:foo@example.com')
assert_raises(URI::InvalidURIError) { uri.user = 'bar' }
assert_raises(URI::InvalidURIError) { uri.password = 'bar' }
assert_raises(URI::InvalidURIError) { uri.userinfo = ['bar', 'baz'] }
assert_raises(URI::InvalidURIError) { uri.host = 'bar' }
assert_raises(URI::InvalidURIError) { uri.port = 'bar' }
assert_raises(URI::InvalidURIError) { uri.path = 'bar' }
assert_raises(URI::InvalidURIError) { uri.query = 'bar' }
end
end