[前][次][番号順一覧][スレッド一覧]

ruby-changes:49981

From: normal <ko1@a...>
Date: Tue, 30 Jan 2018 09:22:28 +0900 (JST)
Subject: [ruby-changes:49981] normal:r62099 (trunk): net/pop: make modified strings mutable

normal	2018-01-30 09:22:22 +0900 (Tue, 30 Jan 2018)

  New Revision: 62099

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62099

  Log:
    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

  Modified files:
    trunk/lib/net/pop.rb
    trunk/test/net/pop/test_pop.rb
Index: lib/net/pop.rb
===================================================================
--- lib/net/pop.rb	(revision 62098)
+++ lib/net/pop.rb	(revision 62099)
@@ -467,7 +467,7 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/pop.rb#L467
 
     # 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 https://github.com/ruby/ruby/blob/trunk/lib/net/pop.rb#L758
 
     # 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 https://github.com/ruby/ruby/blob/trunk/lib/net/pop.rb#L799
     #
     # 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 https://github.com/ruby/ruby/blob/trunk/lib/net/pop.rb#L819
     # 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 https://github.com/ruby/ruby/blob/trunk/lib/net/pop.rb#L831
     # 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 https://github.com/ruby/ruby/blob/trunk/lib/net/pop.rb#L898
     attr_reader :socket
 
     def inspect
-      "#<#{self.class} socket=#{@socket}>"
+      +"#<#{self.class} socket=#{@socket}>"
     end
 
     def auth(account, password)
Index: test/net/pop/test_pop.rb
===================================================================
--- test/net/pop/test_pop.rb	(revision 62098)
+++ test/net/pop/test_pop.rb	(revision 62099)
@@ -64,6 +64,35 @@ class TestPOP < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/net/pop/test_pop.rb#L64
     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)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]