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

ruby-changes:25382

From: kou <ko1@a...>
Date: Sat, 3 Nov 2012 12:42:42 +0900 (JST)
Subject: [ruby-changes:25382] kou:r37439 (trunk): * lib/rexml/xmldecl.rb (REXML::XMLDecl): Stop using REXML::Encoding

kou	2012-11-03 12:41:26 +0900 (Sat, 03 Nov 2012)

  New Revision: 37439

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

  Log:
    * lib/rexml/xmldecl.rb (REXML::XMLDecl): Stop using REXML::Encoding
      module because XMLDecl doesn't convert encoding. This causes
      removing XML encoding name normalization (encoding.upcase).
      Encoding name in XML declaration is what user specifies.
      I think this is reasonable change.
    * test/rexml/test_xml_declaration.rb: Add tests for the above change.

  Modified files:
    trunk/ChangeLog
    trunk/lib/rexml/xmldecl.rb
    trunk/test/rexml/test_xml_declaration.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 37438)
+++ ChangeLog	(revision 37439)
@@ -1,3 +1,12 @@
+Sat Nov  3 12:36:35 2012  Kouhei Sutou  <kou@c...>
+
+	* lib/rexml/xmldecl.rb (REXML::XMLDecl): Stop using REXML::Encoding
+	  module because XMLDecl doesn't convert encoding. This causes
+	  removing XML encoding name normalization (encoding.upcase).
+	  Encoding name in XML declaration is what user specifies.
+	  I think this is reasonable change.
+	* test/rexml/test_xml_declaration.rb: Add tests for the above change.
+
 Sat Nov  3 12:18:35 2012  Masaki Matsushita  <glass.saga@g...>
 
 	* array.c (recursive_equal): fix not to make invalid pointers when
Index: lib/rexml/xmldecl.rb
===================================================================
--- lib/rexml/xmldecl.rb	(revision 37438)
+++ lib/rexml/xmldecl.rb	(revision 37439)
@@ -4,8 +4,6 @@
 module REXML
   # NEEDS DOCUMENTATION
   class XMLDecl < Child
-    include Encoding
-
     DEFAULT_VERSION = "1.0";
     DEFAULT_ENCODING = "UTF-8";
     DEFAULT_STANDALONE = "no";
@@ -13,7 +11,7 @@
     STOP = '\?>';
 
     attr_accessor :version, :standalone
-    attr_reader :writeencoding, :writethis
+    attr_reader :encoding, :writeencoding, :writethis
 
     def initialize(version=DEFAULT_VERSION, encoding=nil, standalone=nil)
       @writethis = true
@@ -57,7 +55,7 @@
     def ==( other )
       other.kind_of?(XMLDecl) and
       other.version == @version and
-      other.encoding == self.encoding and
+      other.encoding.upcase == self.encoding.upcase and
       other.standalone == @standalone
     end
 
@@ -72,14 +70,13 @@
     end
 
     alias :stand_alone? :standalone
-    alias :old_enc= :encoding=
 
     def encoding=( enc )
       if enc.nil?
-        self.old_enc = "UTF-8"
+        @encoding = "UTF-8"
         @writeencoding = false
       else
-        self.old_enc = enc
+        @encoding = enc
         @writeencoding = true
       end
       self.dowrite
Index: test/rexml/test_xml_declaration.rb
===================================================================
--- test/rexml/test_xml_declaration.rb	(revision 37438)
+++ test/rexml/test_xml_declaration.rb	(revision 37439)
@@ -31,4 +31,16 @@
     assert_kind_of(REXML::XMLDecl, @root.previous_sibling.previous_sibling)
     assert_kind_of(REXML::Element, @xml_declaration.next_sibling.next_sibling)
   end
+
+  def test_equal
+    lower_encoding_xml_decl = REXML::XMLDecl.new("1.0", "utf-8")
+    upper_encoding_xml_decl = REXML::XMLDecl.new("1.0", "UTF-8")
+    assert_equal(lower_encoding_xml_decl, upper_encoding_xml_decl)
+  end
+
+  def test_encoding_is_not_normalized
+    lower_encoding_xml_decl = REXML::XMLDecl.new("1.0", "utf-8")
+    assert_equal("<?xml version='1.0' encoding='utf-8'?>",
+                 lower_encoding_xml_decl.to_s)
+  end
 end

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

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