diff options
author | kou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-11-03 03:41:26 +0000 |
---|---|---|
committer | kou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-11-03 03:41:26 +0000 |
commit | 69eedf6a18d0c21b06d30ec4bc4a550d4ac125dd (patch) | |
tree | 66d0a13000e00d69d5ab64598d99f4230a43fa88 | |
parent | c032c5bc9acb015dbe2947a39d3d7ce033c934ee (diff) | |
download | ruby-69eedf6a18d0c21b06d30ec4bc4a550d4ac125dd.tar.gz |
* 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.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37439 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | lib/rexml/xmldecl.rb | 11 | ||||
-rw-r--r-- | test/rexml/test_xml_declaration.rb | 12 |
3 files changed, 25 insertions, 7 deletions
@@ -1,3 +1,12 @@ +Sat Nov 3 12:36:35 2012 Kouhei Sutou <kou@cozmixng.org> + + * 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@gmail.com> * array.c (recursive_equal): fix not to make invalid pointers when diff --git a/lib/rexml/xmldecl.rb b/lib/rexml/xmldecl.rb index 361e4b7106..6b48a6f8ea 100644 --- a/lib/rexml/xmldecl.rb +++ b/lib/rexml/xmldecl.rb @@ -4,8 +4,6 @@ require 'rexml/source' module REXML # NEEDS DOCUMENTATION class XMLDecl < Child - include Encoding - DEFAULT_VERSION = "1.0"; DEFAULT_ENCODING = "UTF-8"; DEFAULT_STANDALONE = "no"; @@ -13,7 +11,7 @@ module REXML 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 @@ module REXML 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 @@ module REXML 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 diff --git a/test/rexml/test_xml_declaration.rb b/test/rexml/test_xml_declaration.rb index d58f9f08ba..16427c7d1a 100644 --- a/test/rexml/test_xml_declaration.rb +++ b/test/rexml/test_xml_declaration.rb @@ -31,4 +31,16 @@ class TestXmlDeclaration < Test::Unit::TestCase 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 |