summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--lib/uri/mailto.rb20
-rw-r--r--test/uri/test_mailto.rb63
-rw-r--r--version.h6
4 files changed, 75 insertions, 20 deletions
diff --git a/ChangeLog b/ChangeLog
index 84c3f8b221..b53afcb8e9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/lib/uri/mailto.rb b/lib/uri/mailto.rb
index 7299550d3f..1494c3952b 100644
--- a/lib/uri/mailto.rb
+++ b/lib/uri/mailto.rb
@@ -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}
"
diff --git a/test/uri/test_mailto.rb b/test/uri/test_mailto.rb
index c09b001e0f..e7d3142198 100644
--- a/test/uri/test_mailto.rb
+++ b/test/uri/test_mailto.rb
@@ -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
diff --git a/version.h b/version.h
index 1ba3808348..9efba7b446 100644
--- a/version.h
+++ b/version.h
@@ -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"