* lib/rexml/document.rb (REXML::Document#write): Add :encoding option
to support custom XML encoding. [Feature #4872] (work in progress) * test/rexml/test_document.rb: Add tests for the above change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37355 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
292c659b5c
commit
af83fcfe4d
@ -1,3 +1,10 @@
|
|||||||
|
Sun Oct 28 15:41:50 2012 Kouhei Sutou <kou@cozmixng.org>
|
||||||
|
|
||||||
|
* lib/rexml/document.rb (REXML::Document#write): Add :encoding option
|
||||||
|
to support custom XML encoding.
|
||||||
|
[Feature #4872] (work in progress)
|
||||||
|
* test/rexml/test_document.rb: Add tests for the above change.
|
||||||
|
|
||||||
Sun Oct 28 15:00:19 2012 Kouhei Sutou <kou@cozmixng.org>
|
Sun Oct 28 15:00:19 2012 Kouhei Sutou <kou@cozmixng.org>
|
||||||
|
|
||||||
* lib/rexml/document.rb (REXML::Document#write): Remove needless
|
* lib/rexml/document.rb (REXML::Document#write): Remove needless
|
||||||
|
@ -207,17 +207,19 @@ module REXML
|
|||||||
indent = options[:indent]
|
indent = options[:indent]
|
||||||
transitive = options[:transitive]
|
transitive = options[:transitive]
|
||||||
ie_hack = options[:ie_hack]
|
ie_hack = options[:ie_hack]
|
||||||
|
encoding = options[:encoding]
|
||||||
else
|
else
|
||||||
output, indent, transitive, ie_hack, = *arguments
|
output, indent, transitive, ie_hack, encoding, = *arguments
|
||||||
end
|
end
|
||||||
|
|
||||||
output ||= $stdout
|
output ||= $stdout
|
||||||
indent ||= -1
|
indent ||= -1
|
||||||
transitive = false if transitive.nil?
|
transitive = false if transitive.nil?
|
||||||
ie_hack = false if ie_hack.nil?
|
ie_hack = false if ie_hack.nil?
|
||||||
|
encoding ||= xml_decl.encoding
|
||||||
|
|
||||||
if xml_decl.encoding != 'UTF-8' && !output.kind_of?(Output)
|
if encoding != 'UTF-8' && !output.kind_of?(Output)
|
||||||
output = Output.new( output, xml_decl.encoding )
|
output = Output.new( output, encoding )
|
||||||
end
|
end
|
||||||
formatter = if indent > -1
|
formatter = if indent > -1
|
||||||
if transitive
|
if transitive
|
||||||
|
@ -159,6 +159,19 @@ EOX
|
|||||||
document.write(output, indent, transitive, ie_hack)
|
document.write(output, indent, transitive, ie_hack)
|
||||||
assert_equal("<empty />", output)
|
assert_equal("<empty />", output)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_encoding
|
||||||
|
output = ""
|
||||||
|
indent = -1
|
||||||
|
transitive = false
|
||||||
|
ie_hack = false
|
||||||
|
encoding = "Shift_JIS"
|
||||||
|
@document.write(output, indent, transitive, ie_hack, encoding)
|
||||||
|
assert_equal(<<-EOX, output)
|
||||||
|
<?xml version='1.0' encoding='SHIFT_JIS'?>
|
||||||
|
<message>Hello world!</message>
|
||||||
|
EOX
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class OptionsTest < self
|
class OptionsTest < self
|
||||||
@ -199,6 +212,15 @@ EOX
|
|||||||
document.write(:output => output, :ie_hack => true)
|
document.write(:output => output, :ie_hack => true)
|
||||||
assert_equal("<empty />", output)
|
assert_equal("<empty />", output)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_encoding
|
||||||
|
output = ""
|
||||||
|
@document.write(:output => output, :encoding => "Shift_JIS")
|
||||||
|
assert_equal(<<-EOX, output)
|
||||||
|
<?xml version='1.0' encoding='SHIFT_JIS'?>
|
||||||
|
<message>Hello world!</message>
|
||||||
|
EOX
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user