summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakira <akira@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-07-13 10:50:26 +0000
committerakira <akira@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-07-13 10:50:26 +0000
commit308977fadcfe002cf7267798ebd585d84281cbd1 (patch)
tree83c021061d6f926ff02185efcbde71827753da9a
parentbd580a0428a73016e45dff77503cd84a6b32c08b (diff)
downloadruby-308977fadcfe002cf7267798ebd585d84281cbd1.tar.gz
ruby-308977fadcfe002cf7267798ebd585d84281cbd1.tar.xz
ruby-308977fadcfe002cf7267798ebd585d84281cbd1.zip
* lib/uri/generic.rb (URI::Generic#merge_path):
"URI('http://www.example.com/foo/..') + './'" should return "URI('http://www.example.com/')". [ruby-list:39838] "URI('http://www.example.com/') + './foo/bar/..'" should return "URI('http://www.example.com/foo/')". [ruby-list:39844] * test/uri/test_generic.rb (TestGeneric#test_merge): added tests. git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@6620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog12
-rw-r--r--lib/uri/generic.rb16
-rw-r--r--test/uri/test_generic.rb27
3 files changed, 48 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index c12edaa12..601fd4cfd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+Tue Jul 13 19:39:12 2004 akira yamada <akira@ruby-lang.org>
+
+ * lib/uri/generic.rb (URI::Generic#merge_path):
+ "URI('http://www.example.com/foo/..') + './'" should return
+ "URI('http://www.example.com/')". [ruby-list:39838]
+ "URI('http://www.example.com/') + './foo/bar/..'" should return
+ "URI('http://www.example.com/foo/')". [ruby-list:39844]
+
+ * test/uri/test_generic.rb (TestGeneric#test_merge): added tests.
+
Tue Jul 13 15:51:45 2004 Akinori MUSHA <knu@iDaemons.org>
* lib/mkmf.rb (init_mkmf): Do not add $(libdir) to $LIBPATH in
@@ -68,7 +78,7 @@ Thu Jul 8 22:52:19 2004 Kouhei Sutou <kou@cozmixng.org>
* test/rss/{test_trackback,rss-testcase}.rb: fixed no good method
name.
-Thu Jul 8 00:05:23 2004 akira yamada <akira@arika.org>
+Thu Jul 8 00:05:23 2004 akira yamada <akira@ruby-lang.org>
* lib/tempfile.rb (Tempfile::initialize): got out code of
generating tmpname. [ruby-dev:23832][ruby-dev:23837]
diff --git a/lib/uri/generic.rb b/lib/uri/generic.rb
index 3d6cc8525..0dedcf494 100644
--- a/lib/uri/generic.rb
+++ b/lib/uri/generic.rb
@@ -630,16 +630,20 @@ module URI
base_path = split_path(base)
rel_path = split_path(rel)
+ # RFC2396, Section 5.2, 6), a)
+ base_path << '' if base_path.last == '..'
+ while i = base_path.index('..')
+ base_path.slice!(i - 1, 2)
+ end
if base_path.empty?
- base_path = [''] # XXX
+ base_path = [''] # keep '/' for root directory
+ else
+ base_path.pop
end
- # RFC2396, Section 5.2, 6), a)
- base_path.pop unless base_path.size == 1
-
# RFC2396, Section 5.2, 6), c)
- # RFC2396, Section 5.2, 6), d)
- rel_path.push('') if rel_path.last == '.'
+ # RFC2396, Section 5.2, 6), d)
+ rel_path.push('') if rel_path.last == '.' || rel_path.last == '..'
rel_path.delete('.')
# RFC2396, Section 5.2, 6), e)
diff --git a/test/uri/test_generic.rb b/test/uri/test_generic.rb
index 770a6f615..8740574e4 100644
--- a/test/uri/test_generic.rb
+++ b/test/uri/test_generic.rb
@@ -163,6 +163,33 @@ class TestGeneric < Test::Unit::TestCase
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))
+
+ # [ruby-list:39838]
+ u0 = URI.parse('http://www.example.com/')
+ u1 = URI.parse('http://www.example.com/foo/..') + './'
+ assert_equal(u0, u1)
+ u0 = URI.parse('http://www.example.com/foo/')
+ u1 = URI.parse('http://www.example.com/foo/bar/..') + './'
+ assert_equal(u0, u1)
+ u0 = URI.parse('http://www.example.com/foo/bar/')
+ u1 = URI.parse('http://www.example.com/foo/bar/baz/..') + './'
+ assert_equal(u0, u1)
+ u0 = URI.parse('http://www.example.com/')
+ u1 = URI.parse('http://www.example.com/foo/bar/../..') + './'
+ assert_equal(u0, u1)
+ u0 = URI.parse('http://www.example.com/foo/')
+ 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)
+ u = URI.parse('http://www.example.com/')
+ u0 = u + './'
+ u1 = u + './foo/bar/../..'
+ assert_equal(u0, u1)
end
def test_route