From 3993fbb5f6bfdae0bce040988d7e2dd632247cdc Mon Sep 17 00:00:00 2001 From: nagachika Date: Sat, 18 Aug 2018 08:35:42 +0000 Subject: merge revision(s) 62099: [Backport #14416] net/pop: make modified strings mutable Thanks to Michael Zimmerman for the bug report * lib/net/pop.rb: make modified strings mutable [ruby-core:85210] [Bug #14416] * test/net/pop/test_pop.rb: new test git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_5@64443 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/net/pop.rb | 12 ++++++------ test/net/pop/test_pop.rb | 29 +++++++++++++++++++++++++++++ version.h | 2 +- 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/lib/net/pop.rb b/lib/net/pop.rb index 55597f2fab..92a4fe7303 100644 --- a/lib/net/pop.rb +++ b/lib/net/pop.rb @@ -467,7 +467,7 @@ module Net # Provide human-readable stringification of class state. def inspect - "#<#{self.class} #{@address}:#{@port} open=#{@started}>" + +"#<#{self.class} #{@address}:#{@port} open=#{@started}>" end # *WARNING*: This method causes a serious security hole. @@ -758,7 +758,7 @@ module Net # Provide human-readable stringification of class state. def inspect - "#<#{self.class} #{@number}#{@deleted ? ' deleted' : ''}>" + +"#<#{self.class} #{@number}#{@deleted ? ' deleted' : ''}>" end # @@ -799,7 +799,7 @@ module Net # # This method raises a POPError if an error occurs. # - def pop( dest = '', &block ) # :yield: message_chunk + def pop( dest = +'', &block ) # :yield: message_chunk if block_given? @command.retr(@number, &block) nil @@ -819,7 +819,7 @@ module Net # The optional +dest+ argument is obsolete. # # This method raises a POPError if an error occurs. - def top(lines, dest = '') + def top(lines, dest = +'') @command.top(@number, lines) do |chunk| dest << chunk end @@ -831,7 +831,7 @@ module Net # The optional +dest+ argument is obsolete. # # This method raises a POPError if an error occurs. - def header(dest = '') + def header(dest = +'') top(0, dest) end @@ -898,7 +898,7 @@ module Net attr_reader :socket def inspect - "#<#{self.class} socket=#{@socket}>" + +"#<#{self.class} socket=#{@socket}>" end def auth(account, password) diff --git a/test/net/pop/test_pop.rb b/test/net/pop/test_pop.rb index 666aac0db6..f4c807a7a8 100644 --- a/test/net/pop/test_pop.rb +++ b/test/net/pop/test_pop.rb @@ -64,6 +64,35 @@ class TestPOP < Test::Unit::TestCase end end + def test_popmail + # totally not representative of real messages, but + # enough to test frozen bugs + lines = [ "[ruby-core:85210]" , "[Bug #14416]" ].freeze + command = Object.new + command.instance_variable_set(:@lines, lines) + + def command.retr(n) + @lines.each { |l| yield "#{l}\r\n" } + end + + def command.top(number, nl) + @lines.each do |l| + yield "#{l}\r\n" + break if (nl -= 1) <= 0 + end + end + + net_pop = :unused + popmail = Net::POPMail.new(1, 123, net_pop, command) + res = popmail.pop + assert_equal "[ruby-core:85210]\r\n[Bug #14416]\r\n", res + assert_not_predicate res, :frozen? + + res = popmail.top(1) + assert_equal "[ruby-core:85210]\r\n", res + assert_not_predicate res, :frozen? + end + def pop_test(apop=false) host = 'localhost' server = TCPServer.new(host, 0) diff --git a/version.h b/version.h index 12161f6ffe..7cdaf04c23 100644 --- a/version.h +++ b/version.h @@ -1,6 +1,6 @@ #define RUBY_VERSION "2.5.2" #define RUBY_RELEASE_DATE "2018-08-18" -#define RUBY_PATCHLEVEL 81 +#define RUBY_PATCHLEVEL 82 #define RUBY_RELEASE_YEAR 2018 #define RUBY_RELEASE_MONTH 8 -- cgit v1.2.3