summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-04-19 11:56:22 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-04-19 11:56:22 +0000
commitcfe710763e7eb44555cd01999534ed569e9fbf44 (patch)
tree7cd47ee99ede0bd1ce681a2a709288b4fce5694a /test
parent09f5560c5721ad779cc2e740c4a77ad6aca1b530 (diff)
Merge this too.
* lib/uri/ftp.rb, lib/uri/generic.rb, test/uri/test_common.rb, test/uri/test_ftp.rb, test/uri/test_generic.rb: backported from 1.9. [ruby-dev:31318] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_7@16085 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/uri/test_common.rb5
-rw-r--r--test/uri/test_ftp.rb22
-rw-r--r--test/uri/test_generic.rb80
3 files changed, 66 insertions, 41 deletions
diff --git a/test/uri/test_common.rb b/test/uri/test_common.rb
index a159901ea6..0fe031bdee 100644
--- a/test/uri/test_common.rb
+++ b/test/uri/test_common.rb
@@ -12,7 +12,6 @@ class TestCommon < Test::Unit::TestCase
end
def test_extract
- # ruby-list:36086
assert_equal(['http://example.com'],
URI.extract('http://example.com'))
assert_equal(['http://example.com'],
@@ -20,9 +19,9 @@ class TestCommon < Test::Unit::TestCase
assert_equal(['http://example.com/foo)'],
URI.extract('(http://example.com/foo)'))
assert_equal(['http://example.jphttp://example.jp'],
- URI.extract('http://example.jphttp://example.jp'))
+ URI.extract('http://example.jphttp://example.jp'), "[ruby-list:36086]")
assert_equal(['http://example.jphttp://example.jp'],
- URI.extract('http://example.jphttp://example.jp', ['http']))
+ URI.extract('http://example.jphttp://example.jp', ['http']), "[ruby-list:36086]")
assert_equal(['http://', 'mailto:'].sort,
URI.extract('ftp:// http:// mailto: https://', ['http', 'mailto']).sort)
# reported by Doug Kearns <djkea2@mugca.its.monash.edu.au>
diff --git a/test/uri/test_ftp.rb b/test/uri/test_ftp.rb
index a7b59efebf..10abd29502 100644
--- a/test/uri/test_ftp.rb
+++ b/test/uri/test_ftp.rb
@@ -15,7 +15,7 @@ class TestFTP < Test::Unit::TestCase
exp = [
'ftp',
'user:pass', 'host.com', URI::FTP.default_port,
- '/abc/def', nil,
+ 'abc/def', nil,
]
ary = [
url.scheme, url.userinfo, url.host, url.port,
@@ -27,6 +27,26 @@ class TestFTP < Test::Unit::TestCase
assert_equal('pass', url.password)
end
+ def test_paths
+ # If you think what's below is wrong, please read RubyForge bug 2055,
+ # RFC 1738 section 3.2.2, and RFC 2396.
+ u = URI.parse('ftp://ftp.example.com/foo/bar/file.ext')
+ assert_equal(u.path, 'foo/bar/file.ext')
+ u = URI.parse('ftp://ftp.example.com//foo/bar/file.ext')
+ assert_equal(u.path, '/foo/bar/file.ext')
+ u = URI.parse('ftp://ftp.example.com/%2Ffoo/bar/file.ext')
+ assert_equal(u.path, '/foo/bar/file.ext')
+ end
+
+ def test_assemble
+ # uri/ftp is conservative and uses the older RFC 1738 rules, rather than
+ # assuming everyone else has implemented RFC 2396.
+ uri = URI::FTP.build(['user:password', 'ftp.example.com', nil,
+ '/path/file.zip', 'i'])
+ assert_equal(uri.to_s,
+ 'ftp://user:password@ftp.example.com/%2Fpath/file.zip;type=i')
+ end
+
def test_select
assert_equal(['ftp', 'a.b.c', 21], URI.parse('ftp://a.b.c/').select(:scheme, :host, :port))
u = URI.parse('ftp://a.b.c/')
diff --git a/test/uri/test_generic.rb b/test/uri/test_generic.rb
index 8a7feb4982..5cd4c7f7ae 100644
--- a/test/uri/test_generic.rb
+++ b/test/uri/test_generic.rb
@@ -38,6 +38,17 @@ class TestGeneric < Test::Unit::TestCase
exp = [
'ftp',
nil, 'ftp.is.co.za', URI::FTP.default_port,
+ 'rfc/rfc1808.txt', nil,
+ ]
+ ary = uri_to_ary(url)
+ assert_equal(exp, ary)
+ # 1'
+ url = URI.parse('ftp://ftp.is.co.za/%2Frfc/rfc1808.txt')
+ assert_kind_of(URI::FTP, url)
+
+ exp = [
+ 'ftp',
+ nil, 'ftp.is.co.za', URI::FTP.default_port,
'/rfc/rfc1808.txt', nil,
]
ary = uri_to_ary(url)
@@ -124,11 +135,10 @@ class TestGeneric < Test::Unit::TestCase
assert_kind_of(URI::Generic, url)
# 9
- # [ruby-dev:25667]
url = URI.parse('ftp://:pass@localhost/')
- assert_equal('', url.user)
+ assert_equal('', url.user, "[ruby-dev:25667]")
assert_equal('pass', url.password)
- assert_equal(':pass', url.userinfo)
+ assert_equal(':pass', url.userinfo, "[ruby-dev:25667]")
url = URI.parse('ftp://user@localhost/')
assert_equal('user', url.user)
assert_equal(nil, url.password)
@@ -155,9 +165,8 @@ class TestGeneric < Test::Unit::TestCase
assert_equal(URI.parse('http://foo/baz'), u3 + '/baz')
assert_equal(URI.parse('http://foo/baz'), u4 + '/baz')
- # from [ruby-dev:11508] Re: uri
url = URI.parse('http://hoge/a.html') + 'b.html'
- assert_equal('http://hoge/b.html', url.to_s)
+ assert_equal('http://hoge/b.html', url.to_s, "[ruby-dev:11508]")
# reported by Mr. Kubota <em6t-kbt@asahi-net.or.jp>
url = URI.parse('http://a/b') + 'http://x/y'
@@ -174,15 +183,13 @@ class TestGeneric < Test::Unit::TestCase
assert(nil != u.merge!("../baz"))
assert_equal('http://foo/baz', u.to_s)
- # [ruby-dev:23628]
u0 = URI.parse('mailto:foo@example.com')
u1 = URI.parse('mailto:foo@example.com#bar')
- assert_equal(uri_to_ary(u0 + '#bar'), uri_to_ary(u1))
+ assert_equal(uri_to_ary(u0 + '#bar'), uri_to_ary(u1), "[ruby-dev:23628]")
- # [ruby-list:39838]
u0 = URI.parse('http://www.example.com/')
u1 = URI.parse('http://www.example.com/foo/..') + './'
- assert_equal(u0, u1)
+ assert_equal(u0, u1, "[ruby-list:39838]")
u0 = URI.parse('http://www.example.com/foo/')
u1 = URI.parse('http://www.example.com/foo/bar/..') + './'
assert_equal(u0, u1)
@@ -196,11 +203,10 @@ class TestGeneric < Test::Unit::TestCase
u1 = URI.parse('http://www.example.com/foo/bar/baz/../..') + './'
assert_equal(u0, u1)
- # [ruby-list:39844]
u = URI.parse('http://www.example.com/')
u0 = u + './foo/'
u1 = u + './foo/bar/..'
- assert_equal(u0, u1)
+ assert_equal(u0, u1, "[ruby-list:39844]")
u = URI.parse('http://www.example.com/')
u0 = u + './'
u1 = u + './foo/bar/../..'
@@ -238,7 +244,7 @@ class TestGeneric < Test::Unit::TestCase
assert_equal('', url.to_s)
end
- def test_rfc2396_examples
+ def test_rfc3986_examples
# http://a/b/c/d;p?q
# g:h = g:h
url = @base_url.merge('g:h')
@@ -296,11 +302,11 @@ class TestGeneric < Test::Unit::TestCase
assert_equal('//g', url.to_s)
# http://a/b/c/d;p?q
-# ?y = http://a/b/c/?y
+# ?y = http://a/b/c/d;p?y
url = @base_url.merge('?y')
assert_kind_of(URI::HTTP, url)
- assert_equal('http://a/b/c/?y', url.to_s)
- url = @base_url.route_to('http://a/b/c/?y')
+ assert_equal('http://a/b/c/d;p?y', url.to_s)
+ url = @base_url.route_to('http://a/b/c/d;p?y')
assert_kind_of(URI::Generic, url)
assert_equal('?y', url.to_s)
@@ -314,11 +320,11 @@ class TestGeneric < Test::Unit::TestCase
assert_equal('g?y', url.to_s)
# http://a/b/c/d;p?q
-# #s = (current document)#s
+# #s = http://a/b/c/d;p?q#s
url = @base_url.merge('#s')
assert_kind_of(URI::HTTP, url)
- assert_equal(@base_url.to_s + '#s', url.to_s)
- url = @base_url.route_to(@base_url.to_s + '#s')
+ assert_equal('http://a/b/c/d;p?q#s', url.to_s)
+ url = @base_url.route_to('http://a/b/c/d;p?q#s')
assert_kind_of(URI::Generic, url)
assert_equal('#s', url.to_s)
@@ -452,22 +458,22 @@ class TestGeneric < Test::Unit::TestCase
assert_equal('', url.to_s)
# http://a/b/c/d;p?q
-# /./g = http://a/./g
+# /./g = http://a/g
url = @base_url.merge('/./g')
assert_kind_of(URI::HTTP, url)
- assert_equal('http://a/./g', url.to_s)
- url = @base_url.route_to('http://a/./g')
- assert_kind_of(URI::Generic, url)
- assert_equal('/./g', url.to_s)
+ assert_equal('http://a/g', url.to_s)
+# url = @base_url.route_to('http://a/./g')
+# assert_kind_of(URI::Generic, url)
+# assert_equal('/./g', url.to_s)
# http://a/b/c/d;p?q
-# /../g = http://a/../g
+# /../g = http://a/g
url = @base_url.merge('/../g')
assert_kind_of(URI::HTTP, url)
- assert_equal('http://a/../g', url.to_s)
- url = @base_url.route_to('http://a/../g')
- assert_kind_of(URI::Generic, url)
- assert_equal('/../g', url.to_s)
+ assert_equal('http://a/g', url.to_s)
+# url = @base_url.route_to('http://a/../g')
+# assert_kind_of(URI::Generic, url)
+# assert_equal('/../g', url.to_s)
# http://a/b/c/d;p?q
# g. = http://a/b/c/g.
@@ -506,24 +512,24 @@ class TestGeneric < Test::Unit::TestCase
assert_equal('..g', url.to_s)
# http://a/b/c/d;p?q
-# ../../../g = http://a/../g
+# ../../../g = http://a/g
url = @base_url.merge('../../../g')
assert_kind_of(URI::HTTP, url)
- assert_equal('http://a/../g', url.to_s)
- url = @base_url.route_to('http://a/../g')
+ assert_equal('http://a/g', url.to_s)
+ url = @base_url.route_to('http://a/g')
assert_kind_of(URI::Generic, url)
- assert('../../../g' != url.to_s) # ok? yes, it confuses you
- assert_equal('/../g', url.to_s) # and it is clearly
+ assert('../../../g' != url.to_s) # ok? yes, it confuses you
+ assert_equal('../../g', url.to_s) # and it is clearly
# http://a/b/c/d;p?q
-# ../../../../g = http://a/../../g
+# ../../../../g = http://a/g
url = @base_url.merge('../../../../g')
assert_kind_of(URI::HTTP, url)
- assert_equal('http://a/../../g', url.to_s)
- url = @base_url.route_to('http://a/../../g')
+ assert_equal('http://a/g', url.to_s)
+ url = @base_url.route_to('http://a/g')
assert_kind_of(URI::Generic, url)
assert('../../../../g' != url.to_s) # ok? yes, it confuses you
- assert_equal('/../../g', url.to_s) # and it is clearly
+ assert_equal('../../g', url.to_s) # and it is clearly
# http://a/b/c/d;p?q
# ./../g = http://a/b/g