summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authoryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-29 22:50:20 +0000
committeryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-29 22:50:20 +0000
commitbc5aeb987f21514f2a96cb3f5ffad33855612c8a (patch)
treed2aae631a17f0a01250ede6d5a2116f8049b416b /lib
parentf0de89f81ae37ed8b12427c375bc5ad06bcfba0e (diff)
merges r31288 and r31289 from trunk into ruby_1_9_2.
-- * 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] -- Add some more tests for the previous fix. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_2@31804 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 4fdfd140fe..c4252fb5bf 100644
--- a/lib/uri/generic.rb
+++ b/lib/uri/generic.rb
@@ -813,30 +813,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?