summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog14
-rw-r--r--lib/rexml/source.rb2
-rw-r--r--test/rexml/test_encoding.rb9
3 files changed, 24 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 2e3e5db..b0891ca 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+Thu Oct 23 17:19:04 2014 Kouhei Sutou <kou@cozmixng.org>
+
+ * 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@cozmixng.org>
* test/rexml/test_encoding.rb
diff --git a/lib/rexml/source.rb b/lib/rexml/source.rb
index a0bbe25..cfafdbd 100644
--- a/lib/rexml/source.rb
+++ b/lib/rexml/source.rb
@@ -285,7 +285,7 @@ module REXML
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, ""
diff --git a/test/rexml/test_encoding.rb b/test/rexml/test_encoding.rb
index 9a41957..058fb97 100644
--- a/test/rexml/test_encoding.rb
+++ b/test/rexml/test_encoding.rb
@@ -94,5 +94,14 @@ module REXMLTests
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