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

ruby-changes:33979

From: nobu <ko1@a...>
Date: Fri, 23 May 2014 21:36:35 +0900 (JST)
Subject: [ruby-changes:33979] nobu:r46060 (trunk): net/protocol.rb: fix SMTP dot stuffing

nobu	2014-05-23 21:36:30 +0900 (Fri, 23 May 2014)

  New Revision: 46060

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=46060

  Log:
    net/protocol.rb: fix SMTP dot stuffing
    
    * net/protocol.rb (using_each_crlf_line): fix SMTP dot-stuffing
      for messages not ending with a new-line.
      [ruby-core:61441] [Bug #9627] [fix GH-616]

  Modified files:
    trunk/ChangeLog
    trunk/lib/net/protocol.rb
    trunk/test/net/protocol/test_protocol.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 46059)
+++ ChangeLog	(revision 46060)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri May 23 21:36:28 2014  Josh Goebel  <dreamer3@g...>
+
+	* net/protocol.rb (using_each_crlf_line): fix SMTP dot-stuffing
+	  for messages not ending with a new-line.
+	  [ruby-core:61441] [Bug #9627] [fix GH-616]
+
 Fri May 23 03:48:08 2014  Eric Wong  <e@8...>
 
 	* gc.c (rb_free_m_tbl): mark function as static
Index: lib/net/protocol.rb
===================================================================
--- lib/net/protocol.rb	(revision 46059)
+++ lib/net/protocol.rb	(revision 46060)
@@ -267,7 +267,7 @@ module Net # :nodoc: https://github.com/ruby/ruby/blob/trunk/lib/net/protocol.rb#L267
     def write_message_0(src)
       prev = @written_bytes
       each_crlf_line(src) do |line|
-        write0 line.sub(/\A\./, '..')
+        write0 dot_stuff(line)
       end
       @written_bytes - prev
     end
@@ -308,11 +308,15 @@ module Net # :nodoc: https://github.com/ruby/ruby/blob/trunk/lib/net/protocol.rb#L308
 
     private
 
+    def dot_stuff(s)
+      s.sub(/\A\./, '..')
+    end
+
     def using_each_crlf_line
       @wbuf = ''
       yield
       if not @wbuf.empty?   # unterminated last line
-        write0 @wbuf.chomp + "\r\n"
+        write0 dot_stuff(@wbuf.chomp) + "\r\n"
       elsif @written_bytes == 0   # empty src
         write0 "\r\n"
       end
Index: test/net/protocol/test_protocol.rb
===================================================================
--- test/net/protocol/test_protocol.rb	(revision 46059)
+++ test/net/protocol/test_protocol.rb	(revision 46060)
@@ -3,6 +3,15 @@ require "net/protocol" https://github.com/ruby/ruby/blob/trunk/test/net/protocol/test_protocol.rb#L3
 require "stringio"
 
 class TestProtocol < Test::Unit::TestCase
+  def test_should_properly_dot_stuff_period_with_no_endline
+    bug9627 = '[ruby-core:61441] [Bug #9627]'
+    sio = StringIO.new("")
+    imio = Net::InternetMessageIO.new(sio)
+    email = "To: bob@a...\nlook, a period with no endline\n."
+    imio.write_message(email)
+    assert_equal("To: bob@a...\r\nlook, a period with no endline\r\n..\r\n.\r\n", sio.string, bug9627)
+  end
+
   def test_each_crlf_line
     assert_output('', '') do
       sio = StringIO.new("")

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

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