mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_3@58147 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
ddd7dd0f8c
commit
4919dbabdb
4 changed files with 75 additions and 20 deletions
|
|
@ -1,3 +1,9 @@
|
|||
Mon Mar 27 20:12:23 2017 Anton Davydov <mail@davydovanton.com>
|
||||
|
||||
* 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@ruby-lang.org>
|
||||
|
||||
* ruby.c (process_options): convert -e script to the encoding
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ module URI
|
|||
# puts m3.to_s -> mailto:listman@example.com?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
|
|||
end
|
||||
end
|
||||
|
||||
return super(tmp)
|
||||
super(tmp)
|
||||
end
|
||||
|
||||
#
|
||||
|
|
@ -187,7 +187,7 @@ module URI
|
|||
end
|
||||
end
|
||||
|
||||
return true
|
||||
true
|
||||
end
|
||||
private :check_to
|
||||
|
||||
|
|
@ -214,7 +214,7 @@ module URI
|
|||
"bad component(expected opaque component): #{v}"
|
||||
end
|
||||
|
||||
return true
|
||||
true
|
||||
end
|
||||
private :check_headers
|
||||
|
||||
|
|
@ -267,22 +267,22 @@ module URI
|
|||
# # => "To: ruby-list@ruby-lang.org\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}
|
||||
"
|
||||
|
|
|
|||
|
|
@ -2,10 +2,7 @@
|
|||
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
|
|||
ok[-1] << {:to => 'listman@example.com', :headers => [['subject', 'subscribe']]}
|
||||
ok[-1] << {:to => 'listman@example.com', :headers => [['subject', 'subscribe']]}
|
||||
|
||||
# mailto:listman@example.com?subject=subscribe
|
||||
ok << ["mailto:listman@example.com?subject=subscribe"]
|
||||
ok[-1] << {:to => 'listman@example.com', :headers => { 'subject' => 'subscribe' }}
|
||||
ok[-1] << {:to => 'listman@example.com', :headers => 'subject=subscribe' }
|
||||
|
||||
ok_all = ok.flatten.join("\0")
|
||||
|
||||
# mailto:joe@example.com?cc=bob@example.com?body=hello ; WRONG!
|
||||
|
|
@ -129,6 +131,56 @@ class TestMailTo < Test::Unit::TestCase
|
|||
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@example.com', nil, nil, 'subject=Ruby')
|
||||
end
|
||||
end
|
||||
|
||||
def test_check_to
|
||||
u = URI::MailTo.build(['joe@example.com', 'subject=Ruby'])
|
||||
|
||||
assert_raise(URI::InvalidComponentError) do
|
||||
u.to = '#1@mail.com'
|
||||
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@ruby-lang.org\nSubject: subscribe\n\n\n"]
|
||||
results[-1] << { to: 'ruby-list@ruby-lang.org', headers: { 'subject' => 'subscribe' } }
|
||||
|
||||
results << ["To: ruby-list@ruby-lang.org\n\nBody\n"]
|
||||
results[-1] << { to: 'ruby-list@ruby-lang.org', headers: { 'body' => 'Body' } }
|
||||
|
||||
results << ["To: ruby-list@ruby-lang.org, cc@ruby-lang.org\n\n\n"]
|
||||
results[-1] << { to: 'ruby-list@ruby-lang.org', headers: { 'to' => 'cc@ruby-lang.org' } }
|
||||
|
||||
results.each do |expected, params|
|
||||
u = URI::MailTo.build(params)
|
||||
assert_equal(expected, u.to_mailtext)
|
||||
end
|
||||
|
||||
u = URI.parse('mailto:ruby-list@ruby-lang.org?Subject=subscribe&cc=myaddr')
|
||||
assert_equal "To: ruby-list@ruby-lang.org\nSubject: subscribe\nCc: myaddr\n\n\n",
|
||||
u.to_mailtext
|
||||
end
|
||||
|
||||
def test_select
|
||||
u = URI.parse('mailto:joe@example.com?cc=bob@example.com&body=hello')
|
||||
assert_equal(uri_to_ary(u), u.select(*u.component))
|
||||
|
|
@ -137,6 +189,3 @@ class TestMailTo < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
#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"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue