summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--lib/uri/generic.rb21
-rw-r--r--test/uri/test_generic.rb16
3 files changed, 37 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index f368f9bbad..29dda9ebbe 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/lib/uri/generic.rb b/lib/uri/generic.rb
index a968101468..c1d0d63cae 100644
--- a/lib/uri/generic.rb
+++ b/lib/uri/generic.rb
@@ -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
diff --git a/test/uri/test_generic.rb b/test/uri/test_generic.rb
index 34876ebaed..25d01f0606 100644
--- a/test/uri/test_generic.rb
+++ b/test/uri/test_generic.rb
@@ -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