* 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/trunk@31288 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
6692ef3c54
commit
835693dac5
@ -1,3 +1,9 @@
|
|||||||
|
Fri Apr 15 15:10:29 2011 Akinori MUSHA <knu@iDaemons.org>
|
||||||
|
|
||||||
|
* 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]
|
||||||
|
|
||||||
Fri Apr 15 14:58:06 2011 Akinori MUSHA <knu@iDaemons.org>
|
Fri Apr 15 14:58:06 2011 Akinori MUSHA <knu@iDaemons.org>
|
||||||
|
|
||||||
* lib/fileutils.rb (FileUtils#touch): Fix corrupted output when
|
* lib/fileutils.rb (FileUtils#touch): Fix corrupted output when
|
||||||
|
@ -862,30 +862,26 @@ module URI
|
|||||||
private :merge0
|
private :merge0
|
||||||
|
|
||||||
def route_from_path(src, dst)
|
def route_from_path(src, dst)
|
||||||
# RFC2396, Section 4.2
|
case dst
|
||||||
return '' if src == dst
|
when src
|
||||||
|
# RFC2396, Section 4.2
|
||||||
src_path = split_path(src)
|
return ''
|
||||||
dst_path = split_path(dst)
|
when %r{(?:\A|/)\.\.?(?:/|\z)}
|
||||||
|
# dst has abnormal absolute path,
|
||||||
# hmm... dst has abnormal absolute path,
|
# like "/./", "/../", "/x/../", ...
|
||||||
# like "/./", "/../", "/x/../", ...
|
|
||||||
if dst_path.include?('..') ||
|
|
||||||
dst_path.include?('.')
|
|
||||||
return dst.dup
|
return dst.dup
|
||||||
end
|
end
|
||||||
|
|
||||||
src_path.pop
|
src_path = src.scan(%r{(?:\A|[^/]+)/})
|
||||||
|
dst_path = dst.scan(%r{(?:\A|[^/]+)/?})
|
||||||
|
|
||||||
# discard same parts
|
# discard same parts
|
||||||
while dst_path.first == src_path.first
|
while !dst_path.empty? && dst_path.first == src_path.first
|
||||||
break if dst_path.empty?
|
|
||||||
|
|
||||||
src_path.shift
|
src_path.shift
|
||||||
dst_path.shift
|
dst_path.shift
|
||||||
end
|
end
|
||||||
|
|
||||||
tmp = dst_path.join('/')
|
tmp = dst_path.join
|
||||||
|
|
||||||
# calculate
|
# calculate
|
||||||
if src_path.empty?
|
if src_path.empty?
|
||||||
|
@ -222,6 +222,9 @@ class URI::TestGeneric < Test::Unit::TestCase
|
|||||||
url = URI.parse('http://hoge/a/b/').route_to('http://hoge/b/')
|
url = URI.parse('http://hoge/a/b/').route_to('http://hoge/b/')
|
||||||
assert_equal('../../b/', url.to_s)
|
assert_equal('../../b/', url.to_s)
|
||||||
|
|
||||||
|
url = URI.parse('http://hoge/a/b/').route_to('http://hoge/a/b')
|
||||||
|
assert_equal('../b', url.to_s)
|
||||||
|
|
||||||
url = URI.parse('http://hoge/a/b/').route_to('http://HOGE/b/')
|
url = URI.parse('http://hoge/a/b/').route_to('http://HOGE/b/')
|
||||||
assert_equal('../../b/', url.to_s)
|
assert_equal('../../b/', url.to_s)
|
||||||
|
|
||||||
@ -230,6 +233,8 @@ class URI::TestGeneric < Test::Unit::TestCase
|
|||||||
|
|
||||||
url = URI.parse('file:///a/b/').route_to('file:///a/b/')
|
url = URI.parse('file:///a/b/').route_to('file:///a/b/')
|
||||||
assert_equal('', url.to_s)
|
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@example.com').route_to('mailto:foo@example.com#bar')
|
url = URI.parse('mailto:foo@example.com').route_to('mailto:foo@example.com#bar')
|
||||||
assert_equal('#bar', url.to_s)
|
assert_equal('#bar', url.to_s)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user