summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-20 22:29:17 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-20 22:29:17 +0000
commit176061e317b0285908fa360d8b28b6e0c6bb202a (patch)
tree0771236b6f411e267dcdee34b83a6294bff9ae4d /lib
parent79a569f458e1ea58d3bf5fe6ddc9604994616daf (diff)
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@ruby-lang.org> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_7@31666 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/uri/generic.rb26
1 files changed, 11 insertions, 15 deletions
diff --git a/lib/uri/generic.rb b/lib/uri/generic.rb
index c855d60610..a4b35854cb 100644
--- a/lib/uri/generic.rb
+++ b/lib/uri/generic.rb
@@ -799,30 +799,26 @@ module URI
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?