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

ruby-changes:35526

From: usa <ko1@a...>
Date: Wed, 17 Sep 2014 14:56:46 +0900 (JST)
Subject: [ruby-changes:35526] usa:r47608 (ruby_2_0_0): merge revision(s) 46391, 46395: [Backport #9766]

usa	2014-09-17 14:56:35 +0900 (Wed, 17 Sep 2014)

  New Revision: 47608

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

  Log:
    merge revision(s) 46391,46395: [Backport #9766]
    
    * lib/csv.rb (CSV#<<): honor explicity given encoding.  based on
      the patch by DAISUKE TANIWAKI <daisuketaniwaki AT gmail.com> at
      [ruby-core:62113].  [Bug #9766]
    
    * lib/csv.rb (CSV#<<): honor explicitly given encoding.  based on

  Modified directories:
    branches/ruby_2_0_0/
  Modified files:
    branches/ruby_2_0_0/ChangeLog
    branches/ruby_2_0_0/lib/csv.rb
    branches/ruby_2_0_0/test/csv/test_encodings.rb
    branches/ruby_2_0_0/version.h
Index: ruby_2_0_0/ChangeLog
===================================================================
--- ruby_2_0_0/ChangeLog	(revision 47607)
+++ ruby_2_0_0/ChangeLog	(revision 47608)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ChangeLog#L1
+Wed Sep 17 14:52:38 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* lib/csv.rb (CSV#<<): honor explicitly given encoding.  based on
+	  the patch by DAISUKE TANIWAKI <daisuketaniwaki AT gmail.com> at
+	  [ruby-core:62113].  [Bug #9766]
+
 Fri Sep 12 11:34:39 2014  Koichi Sasada  <ko1@a...>
 
 	* test/ruby/test_object.rb: extend timeout.
Index: ruby_2_0_0/lib/csv.rb
===================================================================
--- ruby_2_0_0/lib/csv.rb	(revision 47607)
+++ ruby_2_0_0/lib/csv.rb	(revision 47608)
@@ -1146,9 +1146,9 @@ class CSV https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/lib/csv.rb#L1146
       io.seek(0, IO::SEEK_END)
       args.unshift(io)
     else
-      encoding = (args[-1] = args[-1].dup).delete(:encoding) if args.last.is_a?(Hash)
+      encoding = args[-1][:encoding] if args.last.is_a?(Hash)
       str      = ""
-      str.encode!(encoding) if encoding
+      str.force_encoding(encoding) if encoding
       args.unshift(str)
     end
     csv = new(*args)  # wrap
@@ -1512,7 +1512,7 @@ class CSV https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/lib/csv.rb#L1512
     init_headers(options)
     init_comments(options)
 
-    options.delete(:encoding)
+    @force_encoding = !!(encoding || options.delete(:encoding))
     options.delete(:internal_encoding)
     options.delete(:external_encoding)
     unless options.empty?
@@ -1652,10 +1652,13 @@ class CSV https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/lib/csv.rb#L1652
 
     output = row.map(&@quote).join(@col_sep) + @row_sep  # quote and separate
     if @io.is_a?(StringIO)             and
-       output.encoding != raw_encoding and
-       (compatible_encoding = Encoding.compatible?(@io.string, output))
-      @io = StringIO.new(@io.string.force_encoding(compatible_encoding))
-      @io.seek(0, IO::SEEK_END)
+       output.encoding != (encoding = raw_encoding)
+      if @force_encoding
+        output = output.encode(encoding)
+      elsif (compatible_encoding = Encoding.compatible?(@io.string, output))
+        @io.set_encoding(compatible_encoding)
+        @io.seek(0, IO::SEEK_END)
+      end
     end
     @io << output
 
Index: ruby_2_0_0/version.h
===================================================================
--- ruby_2_0_0/version.h	(revision 47607)
+++ ruby_2_0_0/version.h	(revision 47608)
@@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/version.h#L1
 #define RUBY_VERSION "2.0.0"
-#define RUBY_RELEASE_DATE "2014-09-12"
-#define RUBY_PATCHLEVEL 570
+#define RUBY_RELEASE_DATE "2014-09-17"
+#define RUBY_PATCHLEVEL 571
 
 #define RUBY_RELEASE_YEAR 2014
 #define RUBY_RELEASE_MONTH 9
-#define RUBY_RELEASE_DAY 12
+#define RUBY_RELEASE_DAY 17
 
 #include "ruby/version.h"
 
Index: ruby_2_0_0/test/csv/test_encodings.rb
===================================================================
--- ruby_2_0_0/test/csv/test_encodings.rb	(revision 47607)
+++ ruby_2_0_0/test/csv/test_encodings.rb	(revision 47608)
@@ -257,6 +257,14 @@ class TestCSV::Encodings < TestCSV https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/csv/test_encodings.rb#L257
     assert_equal("UTF-8",      data.to_csv.encoding.name)
   end
 
+  def test_explicit_encoding
+    bug9766 = '[ruby-core:62113] [Bug #9766]'
+    s = CSV.generate(encoding: "Windows-31J") do |csv|
+      csv << ["foo".force_encoding("ISO-8859-1"), "\u3042"]
+    end
+    assert_equal(["foo,\u3042\n".encode(Encoding::Windows_31J), Encoding::Windows_31J], [s, s.encoding], bug9766)
+  end
+
   private
 
   def assert_parses(fields, encoding, options = { })

Property changes on: ruby_2_0_0
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r46391,46395


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

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