[#39863] forループの速度 — Masahiro Sato <msato@...>

15 messages 2004/07/20

[#39868] イテレータとfor文 — OOTANI TAKASHI <otn@...5.so-net.ne.jp>

大谷と申します。

31 messages 2004/07/20
[#39886] Re: イテレータとfor文 — Tietew <tietew-ml-ruby-list@...> 2004/07/21

[ruby-list:39845] Re: URI#merge and relative references

From: akira yamada / やまだあきら <akira@...>
Date: 2004-07-08 15:30:03 UTC
List: ruby-list #39845
>>>>> In [ruby-list : No.39844] 
>>>>>	sheepman <sheepman@tcn.zaq.ne.jp> wrote:
> u = URI.parse("http://www.example.com/") + "./foo/bar/.."
> puts u.to_s #=> http://www.example.com/foo
> puts (u + "./").to_s  #=> http://www.example.com/
>
> foo の後ろの "/" が消えてしまうので、その後に "./" を足すと
> ディレクトリである foo が消えてしまいます。

これでどうでしょう:

--- lib/uri/generic.rb	2004-07-08 23:56:52.000000000 +0900
+++ lib/uri/generic.rb	2004-07-08 23:58:39.000000000 +0900
@@ -634,16 +634,16 @@
 	base_path << '' if base_path.last == '..'
 	while i = base_path.index('..')
 	  base_path.slice!(i - 1, 2)
-	end
+        end
         if base_path.empty?
           base_path = [''] # keep '/' for root directory
-	else
+        else
 	  base_path.pop
-	end
+        end
 
         # 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)
--- test/uri/test_generic.rb	2004-07-08 23:56:52.000000000 +0900
+++ test/uri/test_generic.rb	2004-07-08 23:44:43.000000000 +0900
@@ -180,6 +180,16 @@
     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

In This Thread

Prev Next