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

ruby-changes:25393

From: kou <ko1@a...>
Date: Sat, 3 Nov 2012 14:42:54 +0900 (JST)
Subject: [ruby-changes:25393] kou:r37450 (trunk): * lib/rexml/output.rb (REXML::Output): Don't output BOM in middle

kou	2012-11-03 14:42:40 +0900 (Sat, 03 Nov 2012)

  New Revision: 37450

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

  Log:
    * lib/rexml/output.rb (REXML::Output): Don't output BOM in middle
      of the output string.
    * test/rexml/test_document.rb: Add a test for the above change.

  Modified files:
    trunk/ChangeLog
    trunk/lib/rexml/output.rb
    trunk/test/rexml/test_document.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 37449)
+++ ChangeLog	(revision 37450)
@@ -1,3 +1,9 @@
+Sat Nov  3 14:41:17 2012  Kouhei Sutou  <kou@c...>
+
+	* lib/rexml/output.rb (REXML::Output): Don't output BOM in middle
+	  of the output string.
+	* test/rexml/test_document.rb: Add a test for the above change.
+
 Sat Nov  3 14:09:55 2012  Kouhei Sutou  <kou@c...>
 
 	* NEWS: Add an item about REXML::Document#write.
Index: lib/rexml/output.rb
===================================================================
--- lib/rexml/output.rb	(revision 37449)
+++ lib/rexml/output.rb	(revision 37450)
@@ -11,6 +11,11 @@
       self.encoding = encd
 
       @to_utf = encd != 'UTF-8'
+
+      if encoding == "UTF-16"
+        @output << "\ufeff".encode("UTF-16BE")
+        self.encoding = "UTF-16BE"
+      end
     end
 
     def <<( content )
Index: test/rexml/test_document.rb
===================================================================
--- test/rexml/test_document.rb	(revision 37449)
+++ test/rexml/test_document.rb	(revision 37450)
@@ -296,5 +296,24 @@
         assert_equal("UTF-16", document.encoding)
       end
     end
+
+    class WriteTest < self
+      def test_utf_16
+        xml = <<-EOX.encode("UTF-16LE").force_encoding("ASCII-8BIT")
+<?xml version="1.0"?>
+<message>Hello world!</message>
+EOX
+        bom = "\ufeff".encode("UTF-16LE").force_encoding("ASCII-8BIT")
+        document = REXML::Document.new(bom + xml)
+
+        actual_xml = ""
+        document.write(actual_xml)
+        expected_xml = <<-EOX.encode("UTF-16BE")
+\ufeff<?xml version='1.0' encoding='UTF-16'?>
+<message>Hello world!</message>
+EOX
+        assert_equal(expected_xml, actual_xml)
+      end
+    end
   end
 end

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

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