* lib/rexml/parsers/baseparser.rb: Fix a bug that UTF-8 is used
for UTF-16XX encoded XML that doesn't have encoding="UTF-16" in XML declration. * test/rexml/test_document.rb: Add tests for the above change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37363 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a750424cab
commit
a7322e3678
@ -1,3 +1,10 @@
|
|||||||
|
Sun Oct 28 21:40:13 2012 Kouhei Sutou <kou@cozmixng.org>
|
||||||
|
|
||||||
|
* lib/rexml/parsers/baseparser.rb: Fix a bug that UTF-8 is used
|
||||||
|
for UTF-16XX encoded XML that doesn't have encoding="UTF-16" in
|
||||||
|
XML declration.
|
||||||
|
* test/rexml/test_document.rb: Add tests for the above change.
|
||||||
|
|
||||||
Sun Oct 28 21:37:34 2012 Kouhei Sutou <kou@cozmixng.org>
|
Sun Oct 28 21:37:34 2012 Kouhei Sutou <kou@cozmixng.org>
|
||||||
|
|
||||||
* test/rexml/test_document.rb: Group tests that they parse
|
* test/rexml/test_document.rb: Group tests that they parse
|
||||||
|
@ -215,6 +215,9 @@ module REXML
|
|||||||
if need_source_encoding_update?(encoding)
|
if need_source_encoding_update?(encoding)
|
||||||
@source.encoding = encoding
|
@source.encoding = encoding
|
||||||
end
|
end
|
||||||
|
if encoding.nil? and /\AUTF-16(?:BE|LE)\z/i =~ @source.encoding
|
||||||
|
encoding = "UTF-16"
|
||||||
|
end
|
||||||
standalone = STANDALONE.match(results)
|
standalone = STANDALONE.match(results)
|
||||||
standalone = standalone[1] unless standalone.nil?
|
standalone = standalone[1] unless standalone.nil?
|
||||||
return [ :xmldecl, version, encoding, standalone ]
|
return [ :xmldecl, version, encoding, standalone ]
|
||||||
|
@ -240,6 +240,28 @@ EOX
|
|||||||
xml = <<-EOX.encode("UTF-16BE").force_encoding("ASCII-8BIT")
|
xml = <<-EOX.encode("UTF-16BE").force_encoding("ASCII-8BIT")
|
||||||
<?xml version="1.0" encoding="UTF-16"?>
|
<?xml version="1.0" encoding="UTF-16"?>
|
||||||
<message>Hello world!</message>
|
<message>Hello world!</message>
|
||||||
|
EOX
|
||||||
|
bom = "\ufeff".encode("UTF-16BE").force_encoding("ASCII-8BIT")
|
||||||
|
document = REXML::Document.new(bom + xml)
|
||||||
|
assert_equal("UTF-16", document.encoding)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class NoEncodingTest < self
|
||||||
|
def test_utf_16le
|
||||||
|
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)
|
||||||
|
assert_equal("UTF-16", document.encoding)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_utf_16be
|
||||||
|
xml = <<-EOX.encode("UTF-16BE").force_encoding("ASCII-8BIT")
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<message>Hello world!</message>
|
||||||
EOX
|
EOX
|
||||||
bom = "\ufeff".encode("UTF-16BE").force_encoding("ASCII-8BIT")
|
bom = "\ufeff".encode("UTF-16BE").force_encoding("ASCII-8BIT")
|
||||||
document = REXML::Document.new(bom + xml)
|
document = REXML::Document.new(bom + xml)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user