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

ruby-changes:2985

From: ko1@a...
Date: 22 Dec 2007 17:00:17 +0900
Subject: [ruby-changes:2985] shugo - Ruby:r14477 (trunk): * lib/net/imap.rb (encode_utf7): accept UTF-8 strings.

shugo	2007-12-22 17:00:04 +0900 (Sat, 22 Dec 2007)

  New Revision: 14477

  Modified files:
    trunk/ChangeLog
    trunk/lib/net/imap.rb
    trunk/test/net/imap/test_imap.rb

  Log:
    * lib/net/imap.rb (encode_utf7): accept UTF-8 strings.
    * lib/net/imap.rb (decode_utf7): return UTF-8 strings.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/lib/net/imap.rb?r1=14477&r2=14476
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=14477&r2=14476
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/net/imap/test_imap.rb?r1=14477&r2=14476

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 14476)
+++ ChangeLog	(revision 14477)
@@ -1,3 +1,9 @@
+Sat Dec 22 16:58:49 2007  Shugo Maeda  <shugo@r...>
+
+	* lib/net/imap.rb (encode_utf7): accept UTF-8 strings.
+
+	* lib/net/imap.rb (decode_utf7): return UTF-8 strings.
+
 Sat Dec 22 15:56:36 2007  NAKAMURA Usaku  <usa@r...>
 
 	* transcode_data_japanese: typo.
Index: lib/net/imap.rb
===================================================================
--- lib/net/imap.rb	(revision 14476)
+++ lib/net/imap.rb	(revision 14477)
@@ -852,19 +852,19 @@
           end
           base64.unpack("m")[0].unpack("n*").pack("U*")
         end
-      }
+      }.force_encoding("UTF-8")
     end
 
     # Encode a string from UTF-8 format to modified UTF-7.
     def self.encode_utf7(s)
-      return s.gsub(/(&)|([^\x20-\x25\x27-\x7e]+)/n) { |x|
+      return s.gsub(/(&)|([^\x20-\x25\x27-\x7e]+)/u) { |x|
         if $1
           "&-"
         else
           base64 = [x.unpack("U*").pack("n*")].pack("m")
           "&" + base64.delete("=\n").tr("/", ",") + "-"
         end
-      }
+      }.force_encoding("ASCII-8BIT")
     end
 
     private
Index: test/net/imap/test_imap.rb
===================================================================
--- test/net/imap/test_imap.rb	(revision 14476)
+++ test/net/imap/test_imap.rb	(revision 14477)
@@ -3,12 +3,14 @@
 
 class IMAPTest < Test::Unit::TestCase
   def test_encode_utf7
-    s = Net::IMAP.encode_utf7("\357\274\241\357\274\242\357\274\243")
-    assert_equal("&,yH,Iv8j-", s)
+    utf8 = "\357\274\241\357\274\242\357\274\243".force_encoding("UTF-8")
+    s = Net::IMAP.encode_utf7(utf8)
+    assert_equal("&,yH,Iv8j-".force_encoding("UTF-8"), s)
   end
 
   def test_decode_utf7
     s = Net::IMAP.decode_utf7("&,yH,Iv8j-")
-    assert_equal("\357\274\241\357\274\242\357\274\243", s)
+    utf8 = "\357\274\241\357\274\242\357\274\243".force_encoding("UTF-8")
+    assert_equal(utf8, s)
   end
 end

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

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