ruby-changes:19759
From: yugui <ko1@a...>
Date: Mon, 30 May 2011 07:54:27 +0900 (JST)
Subject: [ruby-changes:19759] yugui:r31804 (ruby_1_9_2): merges r31288 and r31289 from trunk into ruby_1_9_2.
yugui 2011-05-30 07:50:20 +0900 (Mon, 30 May 2011) New Revision: 31804 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=31804 Log: 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. Modified files: branches/ruby_1_9_2/ChangeLog branches/ruby_1_9_2/lib/uri/generic.rb branches/ruby_1_9_2/test/uri/test_generic.rb branches/ruby_1_9_2/version.h Index: ruby_1_9_2/ChangeLog =================================================================== --- ruby_1_9_2/ChangeLog (revision 31803) +++ ruby_1_9_2/ChangeLog (revision 31804) @@ -1,3 +1,9 @@ +Fri Apr 15 15:10:29 2011 Akinori MUSHA <knu@i...> + + * 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] + Thu Apr 14 23:43:43 2011 NAKAMURA Usaku <usa@r...> * numeric.c (ruby_float_step): wrong loop condition. Index: ruby_1_9_2/lib/uri/generic.rb =================================================================== --- ruby_1_9_2/lib/uri/generic.rb (revision 31803) +++ ruby_1_9_2/lib/uri/generic.rb (revision 31804) @@ -813,30 +813,26 @@ 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? Index: ruby_1_9_2/version.h =================================================================== --- ruby_1_9_2/version.h (revision 31803) +++ ruby_1_9_2/version.h (revision 31804) @@ -1,5 +1,5 @@ #define RUBY_VERSION "1.9.2" -#define RUBY_PATCHLEVEL 231 +#define RUBY_PATCHLEVEL 232 #define RUBY_VERSION_MAJOR 1 #define RUBY_VERSION_MINOR 9 #define RUBY_VERSION_TEENY 1 Index: ruby_1_9_2/test/uri/test_generic.rb =================================================================== --- ruby_1_9_2/test/uri/test_generic.rb (revision 31803) +++ ruby_1_9_2/test/uri/test_generic.rb (revision 31804) @@ -228,8 +228,19 @@ url = URI.parse('http://hoge/a/b/').route_to('http://MOGE/b/') assert_equal('//MOGE/b/', url.to_s) + url = URI.parse('http://hoge/b').route_to('http://hoge/b/') + assert_equal('b/', url.to_s) + url = URI.parse('http://hoge/b/a').route_to('http://hoge/b/') + assert_equal('./', url.to_s) + url = URI.parse('http://hoge/b/').route_to('http://hoge/b') + assert_equal('../b', url.to_s) + url = URI.parse('http://hoge/b').route_to('http://hoge/b:c') + assert_equal('./b: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') + assert_equal('../b', url.to_s) url = URI.parse('mailto:foo@e...').route_to('mailto:foo@e...#bar') assert_equal('#bar', url.to_s) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/