[前][次][番号順一覧][スレッド一覧]

ruby-changes:19623

From: shyouhei <ko1@a...>
Date: Sat, 21 May 2011 07:29:32 +0900 (JST)
Subject: [ruby-changes:19623] shyouhei:r31666 (ruby_1_8_7): merge revision(s) 31578:

shyouhei	2011-05-21 07:29:17 +0900 (Sat, 21 May 2011)

  New Revision: 31666

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=31666

  Log:
    merge revision(s) 31578:
    
    * lib/uri/generic.rb (#route_from_path): Fix a bug where
      URI('http://h/b/').route_to('http://h/b') wrongly returned './'
      (should be '../b'). [Bug #4476]
    
    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@31578 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    Signed-off-by: URABE, Shyouhei <shyouhei@r...>

  Modified files:
    branches/ruby_1_8_7/ChangeLog
    branches/ruby_1_8_7/lib/uri/generic.rb
    branches/ruby_1_8_7/test/uri/test_generic.rb
    branches/ruby_1_8_7/version.h

Index: ruby_1_8_7/ChangeLog
===================================================================
--- ruby_1_8_7/ChangeLog	(revision 31665)
+++ ruby_1_8_7/ChangeLog	(revision 31666)
@@ -1,3 +1,9 @@
+Sat May 21 04:55:15 2011  Akinori MUSHA  <knu@i...>
+
+	* lib/uri/generic.rb (#route_from_path): Fix a bug where
+	  URI('http://h/b/').route_to('http://h/b') wrongly returned './'
+	  (should be '../b'). [Bug #4476]
+
 Sat May 21 04:54:20 2011  Akinori MUSHA  <knu@i...>
 
 	* lib/fileutils.rb (FileUtils#touch): Fix corrupted output.
Index: ruby_1_8_7/version.h
===================================================================
--- ruby_1_8_7/version.h	(revision 31665)
+++ ruby_1_8_7/version.h	(revision 31666)
@@ -2,7 +2,7 @@
 #define RUBY_RELEASE_DATE "2011-05-21"
 #define RUBY_VERSION_CODE 187
 #define RUBY_RELEASE_CODE 20110521
-#define RUBY_PATCHLEVEL 343
+#define RUBY_PATCHLEVEL 344
 
 #define RUBY_VERSION_MAJOR 1
 #define RUBY_VERSION_MINOR 8
Index: ruby_1_8_7/lib/uri/generic.rb
===================================================================
--- ruby_1_8_7/lib/uri/generic.rb	(revision 31665)
+++ ruby_1_8_7/lib/uri/generic.rb	(revision 31666)
@@ -799,30 +799,26 @@
     private :merge0
 
     def route_from_path(src, dst)
-      # RFC2396, Section 4.2
-      return '' if src == dst
-
-      src_path = split_path(src)
-      dst_path = split_path(dst)
-
-      # hmm... dst has abnormal absolute path, 
-      # like "/./", "/../", "/x/../", ...
-      if dst_path.include?('..') ||
-          dst_path.include?('.')
+      case dst
+      when src
+        # RFC2396, Section 4.2
+        return ''
+      when %r{(?:\A|/)\.\.?(?:/|\z)}
+        # dst has abnormal absolute path,
+        # like "/./", "/../", "/x/../", ...
         return dst.dup
       end
 
-      src_path.pop
+      src_path = src.scan(%r{(?:\A|[^/]+)/})
+      dst_path = dst.scan(%r{(?:\A|[^/]+)/?})
 
       # discard same parts
-      while dst_path.first == src_path.first
-        break if dst_path.empty?
-
+      while !dst_path.empty? && dst_path.first == src_path.first
         src_path.shift
         dst_path.shift
       end
 
-      tmp = dst_path.join('/')
+      tmp = dst_path.join
 
       # calculate
       if src_path.empty?
Index: ruby_1_8_7/test/uri/test_generic.rb
===================================================================
--- ruby_1_8_7/test/uri/test_generic.rb	(revision 31665)
+++ ruby_1_8_7/test/uri/test_generic.rb	(revision 31666)
@@ -231,8 +231,19 @@
     url = URI.parse('http://hoge/a/b/').route_to('http://MOGE/b/')
     assert_equal('//MOGE/b/', url.to_s)
 
+    url = URI.parse('http://hoge/b').route_to('http://hoge/b/')
+    assert_equal('b/', url.to_s)
+    url = URI.parse('http://hoge/b/a').route_to('http://hoge/b/')
+    assert_equal('./', url.to_s)
+    url = URI.parse('http://hoge/b/').route_to('http://hoge/b')
+    assert_equal('../b', url.to_s)
+    url = URI.parse('http://hoge/b').route_to('http://hoge/b:c')
+    assert_equal('./b:c', url.to_s)
+
     url = URI.parse('file:///a/b/').route_to('file:///a/b/')
     assert_equal('', url.to_s)
+    url = URI.parse('file:///a/b/').route_to('file:///a/b')
+    assert_equal('../b', url.to_s)
 
     url = URI.parse('mailto:foo@e...').route_to('mailto:foo@e...#bar')
     assert_equal('#bar', url.to_s)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]