ruby-changes:46076
From: nagachika <ko1@a...>
Date: Mon, 27 Mar 2017 20:13:37 +0900 (JST)
Subject: [ruby-changes:46076] nagachika:r58147 (ruby_2_3): merge revision(s) 56139, 57066, 57099, 57100: [Backport #10774]
nagachika 2017-03-27 20:13:31 +0900 (Mon, 27 Mar 2017) New Revision: 58147 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58147 Log: merge revision(s) 56139,57066,57099,57100: [Backport #10774] * lib/uri/mailto.rb: Removed needless `return` and use `.`` instead of `::` with class method. * test/uri/test_mailto.rb: Added tests for coverage. Use URI.decode_www_form_component [Bug #10774] `parser` refered RFC2396_Parser, but it is separated. test is contributed by Dominik Menke test_mailto.rb: adjust scope test_mailto.rb: overwritten methods * test/uri/test_mailto.rb (URI::TestMailTo#test_to_mailtext): merge overwritten methods. [Bug #10774] Modified directories: branches/ruby_2_3/ Modified files: branches/ruby_2_3/ChangeLog branches/ruby_2_3/lib/uri/mailto.rb branches/ruby_2_3/test/uri/test_mailto.rb branches/ruby_2_3/version.h Index: ruby_2_3/ChangeLog =================================================================== --- ruby_2_3/ChangeLog (revision 58146) +++ ruby_2_3/ChangeLog (revision 58147) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/ChangeLog#L1 +Mon Mar 27 20:12:23 2017 Anton Davydov <mail@d...> + + * lib/uri/mailto.rb: Removed needless `return` and use `.`` instead of `::` + with class method. + * test/uri/test_mailto.rb: Added tests for coverage. + Mon Mar 20 06:35:08 2017 Nobuyoshi Nakada <nobu@r...> * ruby.c (process_options): convert -e script to the encoding Index: ruby_2_3/lib/uri/mailto.rb =================================================================== --- ruby_2_3/lib/uri/mailto.rb (revision 58146) +++ ruby_2_3/lib/uri/mailto.rb (revision 58147) @@ -84,7 +84,7 @@ module URI https://github.com/ruby/ruby/blob/trunk/ruby_2_3/lib/uri/mailto.rb#L84 # puts m3.to_s -> mailto:listman@e...?subject=subscribe # def self.build(args) - tmp = Util::make_components_hash(self, args) + tmp = Util.make_components_hash(self, args) case tmp[:to] when Array @@ -118,7 +118,7 @@ module URI https://github.com/ruby/ruby/blob/trunk/ruby_2_3/lib/uri/mailto.rb#L118 end end - return super(tmp) + super(tmp) end # @@ -187,7 +187,7 @@ module URI https://github.com/ruby/ruby/blob/trunk/ruby_2_3/lib/uri/mailto.rb#L187 end end - return true + true end private :check_to @@ -214,7 +214,7 @@ module URI https://github.com/ruby/ruby/blob/trunk/ruby_2_3/lib/uri/mailto.rb#L214 "bad component(expected opaque component): #{v}" end - return true + true end private :check_headers @@ -267,22 +267,22 @@ module URI https://github.com/ruby/ruby/blob/trunk/ruby_2_3/lib/uri/mailto.rb#L267 # # => "To: ruby-list@r...\nSubject: subscribe\nCc: myaddr\n\n\n" # def to_mailtext - to = parser.unescape(@to) + to = URI.decode_www_form_component(@to) head = '' body = '' @headers.each do |x| case x[0] when 'body' - body = parser.unescape(x[1]) + body = URI.decode_www_form_component(x[1]) when 'to' - to << ', ' + parser.unescape(x[1]) + to << ', ' + URI.decode_www_form_component(x[1]) else - head << parser.unescape(x[0]).capitalize + ': ' + - parser.unescape(x[1]) + "\n" + head << URI.decode_www_form_component(x[0]).capitalize + ': ' + + URI.decode_www_form_component(x[1]) + "\n" end end - return "To: #{to} + "To: #{to} #{head} #{body} " Index: ruby_2_3/test/uri/test_mailto.rb =================================================================== --- ruby_2_3/test/uri/test_mailto.rb (revision 58146) +++ ruby_2_3/test/uri/test_mailto.rb (revision 58147) @@ -2,10 +2,7 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/uri/test_mailto.rb#L2 require 'test/unit' require 'uri/mailto' -module URI - - -class TestMailTo < Test::Unit::TestCase +class URI::TestMailTo < Test::Unit::TestCase def setup @u = URI::MailTo end @@ -97,6 +94,11 @@ class TestMailTo < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/uri/test_mailto.rb#L94 ok[-1] << {:to => 'listman@e...', :headers => [['subject', 'subscribe']]} ok[-1] << {:to => 'listman@e...', :headers => [['subject', 'subscribe']]} + # mailto:listman@e...?subject=subscribe + ok << ["mailto:listman@e...?subject=subscribe"] + ok[-1] << {:to => 'listman@e...', :headers => { 'subject' => 'subscribe' }} + ok[-1] << {:to => 'listman@e...', :headers => 'subject=subscribe' } + ok_all = ok.flatten.join("\0") # mailto:joe@e...?cc=bob@e...?body=hello ; WRONG! @@ -129,6 +131,56 @@ class TestMailTo < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/uri/test_mailto.rb#L131 assert_equal(ok_all, ok.flatten.join("\0")) end + def test_initializer + assert_raise(URI::InvalidComponentError) do + URI::MailTo.new('mailto', 'sdmitry:bla', 'localhost', '2000', nil, + 'joe@e...', nil, nil, 'subject=Ruby') + end + end + + def test_check_to + u = URI::MailTo.build(['joe@e...', 'subject=Ruby']) + + assert_raise(URI::InvalidComponentError) do + u.to = '#1@m...' + end + + assert_raise(URI::InvalidComponentError) do + u.to = '@invalid.email' + end + end + + def test_to_s + u = URI::MailTo.build([nil, 'subject=Ruby']) + + u.send(:set_to, nil) + assert_equal('mailto:?subject=Ruby', u.to_s) + + u.fragment = 'test' + assert_equal('mailto:?subject=Ruby#test', u.to_s) + end + + def test_to_mailtext + results = [] + results << ["To: ruby-list@r...\nSubject: subscribe\n\n\n"] + results[-1] << { to: 'ruby-list@r...', headers: { 'subject' => 'subscribe' } } + + results << ["To: ruby-list@r...\n\nBody\n"] + results[-1] << { to: 'ruby-list@r...', headers: { 'body' => 'Body' } } + + results << ["To: ruby-list@r..., cc@r...\n\n\n"] + results[-1] << { to: 'ruby-list@r...', headers: { 'to' => 'cc@r...' } } + + results.each do |expected, params| + u = URI::MailTo.build(params) + assert_equal(expected, u.to_mailtext) + end + + u = URI.parse('mailto:ruby-list@r...?Subject=subscribe&cc=myaddr') + assert_equal "To: ruby-list@r...\nSubject: subscribe\nCc: myaddr\n\n\n", + u.to_mailtext + end + def test_select u = URI.parse('mailto:joe@e...?cc=bob@e...&body=hello') assert_equal(uri_to_ary(u), u.select(*u.component)) @@ -137,6 +189,3 @@ class TestMailTo < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/uri/test_mailto.rb#L189 end end end - - -end Index: ruby_2_3/version.h =================================================================== --- ruby_2_3/version.h (revision 58146) +++ ruby_2_3/version.h (revision 58147) @@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/version.h#L1 #define RUBY_VERSION "2.3.3" -#define RUBY_RELEASE_DATE "2017-03-22" -#define RUBY_PATCHLEVEL 259 +#define RUBY_RELEASE_DATE "2017-03-27" +#define RUBY_PATCHLEVEL 260 #define RUBY_RELEASE_YEAR 2017 #define RUBY_RELEASE_MONTH 3 -#define RUBY_RELEASE_DAY 22 +#define RUBY_RELEASE_DAY 27 #include "ruby/version.h" Property changes on: ruby_2_3 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r56139,57066,57099-57100 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/