ruby-changes:36028
From: kou <ko1@a...>
Date: Thu, 23 Oct 2014 17:23:17 +0900 (JST)
Subject: [ruby-changes:36028] kou:r48109 (trunk): * lib/rexml/source.rb (REXML::IOSource#encoding_updated): Fix a
kou 2014-10-23 17:23:10 +0900 (Thu, 23 Oct 2014) New Revision: 48109 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=48109 Log: * lib/rexml/source.rb (REXML::IOSource#encoding_updated): Fix a bug that can't parse XML correctly when Encoding.default_internal is different with XML encoding. REXML::Source converts XML encoding on read. So IO should not convert XML encoding. Based on patch by NAKAMURA Usaku. [ruby-dev:48686] [Bug #10418] * test/rexml/test_encoding.rb (REXMLTests::EncodingTester#test_parse_utf16_with_utf8_default_internal): Add the for the above case. Modified files: trunk/ChangeLog trunk/lib/rexml/source.rb trunk/test/rexml/test_encoding.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 48108) +++ ChangeLog (revision 48109) @@ -1,3 +1,17 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Oct 23 17:19:04 2014 Kouhei Sutou <kou@c...> + + * lib/rexml/source.rb (REXML::IOSource#encoding_updated): Fix a + bug that can't parse XML correctly when + Encoding.default_internal is different with XML + encoding. REXML::Source converts XML encoding on read. So IO + should not convert XML encoding. + Based on patch by NAKAMURA Usaku. + [ruby-dev:48686] [Bug #10418] + + * test/rexml/test_encoding.rb + (REXMLTests::EncodingTester#test_parse_utf16_with_utf8_default_internal): + Add the for the above case. + Thu Oct 23 16:29:02 2014 Kouhei Sutou <kou@c...> * test/rexml/test_encoding.rb Index: lib/rexml/source.rb =================================================================== --- lib/rexml/source.rb (revision 48108) +++ lib/rexml/source.rb (revision 48109) @@ -285,7 +285,7 @@ module REXML https://github.com/ruby/ruby/blob/trunk/lib/rexml/source.rb#L285 case @encoding when "UTF-16BE", "UTF-16LE" @source.binmode - @source.set_encoding(@encoding) + @source.set_encoding(@encoding, @encoding) end @line_break = encode(">") @pending_buffer, @buffer = @buffer, "" Index: test/rexml/test_encoding.rb =================================================================== --- test/rexml/test_encoding.rb (revision 48108) +++ test/rexml/test_encoding.rb (revision 48109) @@ -94,5 +94,14 @@ module REXMLTests https://github.com/ruby/ruby/blob/trunk/test/rexml/test_encoding.rb#L94 assert_equal("UTF-16", utf16.encoding) assert( utf16[0].kind_of?(REXML::XMLDecl)) end + + def test_parse_utf16_with_utf8_default_internal + EnvUtil.with_default_internal("UTF-8") do + utf16 = File.open(fixture_path("utf16.xml")) do |f| + REXML::Document.new(f) + end + assert_equal("UTF-16", utf16.encoding) + end + end end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/