mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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:
parent
53ebcbf733
commit
4bb0fd231e
3 changed files with 37 additions and 9 deletions
|
@ -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>
|
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.
|
* test/xsd/test_noencoding.rb: rescue Errno::EINVAL and do not test.
|
||||||
|
|
|
@ -265,23 +265,22 @@ Object
|
||||||
# methods for userinfo
|
# methods for userinfo
|
||||||
#
|
#
|
||||||
def check_userinfo(user, password = nil)
|
def check_userinfo(user, password = nil)
|
||||||
if (user || password) &&
|
|
||||||
(@registry || @opaque)
|
|
||||||
raise InvalidURIError,
|
|
||||||
"can not set userinfo with registry or opaque"
|
|
||||||
end
|
|
||||||
|
|
||||||
if !password
|
if !password
|
||||||
user, password = split_userinfo(user)
|
user, password = split_userinfo(user)
|
||||||
end
|
end
|
||||||
check_user(user)
|
check_user(user)
|
||||||
check_password(password)
|
check_password(password, user)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
private :check_userinfo
|
private :check_userinfo
|
||||||
|
|
||||||
def check_user(v)
|
def check_user(v)
|
||||||
|
if @registry || @opaque
|
||||||
|
raise InvalidURIError,
|
||||||
|
"can not set user with registry or opaque"
|
||||||
|
end
|
||||||
|
|
||||||
return v unless v
|
return v unless v
|
||||||
|
|
||||||
if USERINFO !~ v
|
if USERINFO !~ v
|
||||||
|
@ -293,10 +292,14 @@ Object
|
||||||
end
|
end
|
||||||
private :check_user
|
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
|
return v unless v
|
||||||
|
|
||||||
if !@password
|
if !user
|
||||||
raise InvalidURIError,
|
raise InvalidURIError,
|
||||||
"password component depends user component"
|
"password component depends user component"
|
||||||
end
|
end
|
||||||
|
|
|
@ -619,6 +619,22 @@ class TestGeneric < Test::Unit::TestCase
|
||||||
assert_equal('http://foo:bar@zab:8080/?a=1', uri.to_s)
|
assert_equal('http://foo:bar@zab:8080/?a=1', uri.to_s)
|
||||||
assert_equal('b123', uri.fragment = 'b123')
|
assert_equal('b123', uri.fragment = 'b123')
|
||||||
assert_equal('http://foo:bar@zab:8080/?a=1#b123', uri.to_s)
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue