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

ruby-changes:49103

From: knu <ko1@a...>
Date: Thu, 14 Dec 2017 10:11:37 +0900 (JST)
Subject: [ruby-changes:49103] knu:r61218 (trunk): Allow empty path components in a URI [Bug #8352]

knu	2017-12-14 10:11:28 +0900 (Thu, 14 Dec 2017)

  New Revision: 61218

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61218

  Log:
    Allow empty path components in a URI [Bug #8352]
    
    * generic.rb (URI::Generic#merge, URI::Generic#route_to): Fix a bug
      where a sequence of slashes in the path part gets collapsed to a
      single slash.  According to the relevant RFCs and WHATWG URL
      Standard, empty path components are simply valid and there is no
      special treatment defined for them, so we just keep them as they
      are.

  Modified files:
    trunk/NEWS
    trunk/lib/uri/generic.rb
    trunk/test/uri/test_generic.rb
Index: lib/uri/generic.rb
===================================================================
--- lib/uri/generic.rb	(revision 61217)
+++ lib/uri/generic.rb	(revision 61218)
@@ -979,7 +979,7 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/generic.rb#L979
     # returns an Array of the path split on '/'
     #
     def split_path(path)
-      path.split(%r{/+}, -1)
+      path.split(%r{/}, -1)
     end
     private :split_path
 
@@ -1154,8 +1154,8 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/generic.rb#L1154
         return dst.dup
       end
 
-      src_path = src.scan(%r{(?:\A|[^/]+)/})
-      dst_path = dst.scan(%r{(?:\A|[^/]+)/?})
+      src_path = src.scan(%r{[^/]*/})
+      dst_path = dst.scan(%r{[^/]*/?})
 
       # discard same parts
       while !dst_path.empty? && dst_path.first == src_path.first
Index: NEWS
===================================================================
--- NEWS	(revision 61217)
+++ NEWS	(revision 61218)
@@ -353,6 +353,10 @@ with all sufficient information, see the https://github.com/ruby/ruby/blob/trunk/NEWS#L353
 
     * StringScanner#size, StringScanner#captures, StringScanner#values_at  [Feature #836]
 
+* URI
+
+  * Relative path operations no longer collapse consecutive slashes to a single slash. [Bug #8352]
+
 * WEBrick
 
   * Add Server Name Indication (SNI) support [Feature #13729]
Index: test/uri/test_generic.rb
===================================================================
--- test/uri/test_generic.rb	(revision 61217)
+++ test/uri/test_generic.rb	(revision 61218)
@@ -208,6 +208,9 @@ class URI::TestGeneric < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/test/uri/test_generic.rb#L208
     assert(nil != u.merge!("../baz"))
     assert_equal('http://foo/baz', u.to_s)
 
+    url = URI.parse('http://a/b//c') + 'd//e'
+    assert_equal('http://a/b//d//e', url.to_s)
+
     u0 = URI.parse('mailto:foo@e...')
     u1 = URI.parse('mailto:foo@e...#bar')
     assert_equal(uri_to_ary(u0 + '#bar'), uri_to_ary(u1), "[ruby-dev:23628]")
@@ -265,6 +268,9 @@ class URI::TestGeneric < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/test/uri/test_generic.rb#L268
     url = URI.parse('http://hoge/b').route_to('http://hoge/b:c')
     assert_equal('./b:c', url.to_s)
 
+    url = URI.parse('http://hoge/b//c').route_to('http://hoge/b/c')
+    assert_equal('../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')

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

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