[ruby-dev:48688] [ruby-trunk - Bug #10418] REXML's encoding is broken if reading UTF-16 XML and Encondig.default_internal is set

From: usa@...
Date: 2014-10-22 16:08:58 UTC
List: ruby-dev #48688
Issue #10418 has been updated by Usaku NAKAMURA.

Related to Bug #10417: IO#set_encoding without int_enc doesn't keep current=
 internal encoding added

----------------------------------------
Bug #10418: REXML's encoding is broken if reading UTF-16 XML and Encondig.d=
efault_internal is set
https://bugs.ruby-lang.org/issues/10418#change-49583

* Author: Usaku NAKAMURA
* Status: Assigned
* Priority: Normal
* Assignee: Kouhei Sutou
* Category: lib
* Target version: current: 2.2.0
* ruby -v: -
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
`Encoding.default_internal`=E3=81=8C=E3=82=BB=E3=83=83=E3=83=88=E3=81=95=E3=
=82=8C=E3=81=A6=E3=81=84=E3=82=8B=E7=8A=B6=E6=85=8B=E3=81=A7REXML=E3=81=ABU=
TF-16=E3=81=AAIO=E3=82=92=E9=A3=9F=E3=82=8F=E3=81=9B=E3=82=8B=E3=81=A8=E3=
=80=81`REXML::Document#encoding`=E3=81=8CUTF-16=E3=81=A7=E3=81=AF=E3=81=AA=
=E3=81=8F`Encoding.default_internal`=E3=81=AB=E3=81=AA=E3=82=8A=E3=81=BE=E3=
=81=99=E3=80=82
=E4=BB=A5=E4=B8=8B=E3=83=91=E3=83=83=E3=83=81=E3=80=82

~~~
Index: lib/rexml/source.rb
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- lib/rexml/source.rb	(revision 48095)
+++ lib/rexml/source.rb	(working copy)
@@ -285,7 +285,7 @@
       case @encoding
       when "UTF-16BE", "UTF-16LE"
         @source.binmode
-        @source.set_encoding(@encoding)
+        @source.set_encoding(@encoding, @encoding)
       end
       @line_break =3D encode(">")
       @pending_buffer, @buffer =3D @buffer, ""
Index: test/rexml/test_encoding.rb
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- test/rexml/test_encoding.rb	(revision 48095)
+++ test/rexml/test_encoding.rb	(working copy)
@@ -91,8 +91,18 @@
       utf16 =3D File.open(fixture_path("ticket_110_utf16.xml")) do |f|
         REXML::Document.new(f)
       end
-      assert_equal(utf16.encoding, "UTF-16")
+      assert_equal("UTF-16", utf16.encoding)
       assert( utf16[0].kind_of?(REXML::XMLDecl))
     end
+
+    def test_default_internal_with_utf16
+      orig_internal =3D ::Encoding.default_internal
+      ::Encoding.default_internal =3D 'utf-8'
+      begin
+        test_ticket_110
+      ensure
+        ::Encoding.default_internal =3D orig_internal
+      end
+    end
   end
 end

~~~



--=20
https://bugs.ruby-lang.org/

In This Thread

Prev Next