зеркало из https://github.com/github/ruby.git
* lib/rexml/output.rb (REXML::Output): Don't output BOM in middle
of the output string. * test/rexml/test_document.rb: Add a test for the above change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37450 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
15a743b3ff
Коммит
ac9a8ac624
|
@ -1,3 +1,9 @@
|
|||
Sat Nov 3 14:41:17 2012 Kouhei Sutou <kou@cozmixng.org>
|
||||
|
||||
* lib/rexml/output.rb (REXML::Output): Don't output BOM in middle
|
||||
of the output string.
|
||||
* test/rexml/test_document.rb: Add a test for the above change.
|
||||
|
||||
Sat Nov 3 14:09:55 2012 Kouhei Sutou <kou@cozmixng.org>
|
||||
|
||||
* NEWS: Add an item about REXML::Document#write.
|
||||
|
|
|
@ -11,6 +11,11 @@ module REXML
|
|||
self.encoding = encd
|
||||
|
||||
@to_utf = encd != 'UTF-8'
|
||||
|
||||
if encoding == "UTF-16"
|
||||
@output << "\ufeff".encode("UTF-16BE")
|
||||
self.encoding = "UTF-16BE"
|
||||
end
|
||||
end
|
||||
|
||||
def <<( content )
|
||||
|
|
|
@ -296,5 +296,24 @@ EOX
|
|||
assert_equal("UTF-16", document.encoding)
|
||||
end
|
||||
end
|
||||
|
||||
class WriteTest < self
|
||||
def test_utf_16
|
||||
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)
|
||||
|
||||
actual_xml = ""
|
||||
document.write(actual_xml)
|
||||
expected_xml = <<-EOX.encode("UTF-16BE")
|
||||
\ufeff<?xml version='1.0' encoding='UTF-16'?>
|
||||
<message>Hello world!</message>
|
||||
EOX
|
||||
assert_equal(expected_xml, actual_xml)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Загрузка…
Ссылка в новой задаче