1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61218 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
knu 2017-12-14 01:11:28 +00:00
parent f5090e2f5c
commit b53ec390d1
3 changed files with 13 additions and 3 deletions

4
NEWS
View file

@ -353,6 +353,10 @@ with all sufficient information, see the ChangeLog file or Redmine
* 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]

View file

@ -979,7 +979,7 @@ module URI
# 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
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

View file

@ -208,6 +208,9 @@ class URI::TestGeneric < Test::Unit::TestCase
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@example.com')
u1 = URI.parse('mailto:foo@example.com#bar')
assert_equal(uri_to_ary(u0 + '#bar'), uri_to_ary(u1), "[ruby-dev:23628]")
@ -265,6 +268,9 @@ class URI::TestGeneric < Test::Unit::TestCase
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')