Index: lib/builder/xmlbase.rb =================================================================== RCS file: /var/cvs/builder/builder/lib/builder/xmlbase.rb,v retrieving revision 1.4 diff -u -r1.4 xmlbase.rb --- lib/builder/xmlbase.rb 31 Jan 2006 00:18:46 -0000 1.4 +++ lib/builder/xmlbase.rb 10 May 2006 17:38:42 -0000 @@ -19,9 +19,10 @@ # indentation and no line breaks). # initial:: Level of initial indentation. # - def initialize(indent=0, initial=0) - @indent = indent - @level = initial + def initialize(indent=0, initial=0, encoding='utf-8') + @indent = indent + @level = initial + @encoding = encoding end # Create a tag named +sym+. Other than the first argument which @@ -113,7 +114,11 @@ require 'builder/xchar' def _escape(text) - text.to_xs + if @encoding == 'utf-8': + text.to_xs + else + text + end end def _escape_quote(text) Index: lib/builder/xmlmarkup.rb =================================================================== RCS file: /var/cvs/builder/builder/lib/builder/xmlmarkup.rb,v retrieving revision 1.6 diff -u -r1.6 xmlmarkup.rb --- lib/builder/xmlmarkup.rb 30 Mar 2006 19:14:27 -0000 1.6 +++ lib/builder/xmlmarkup.rb 10 May 2006 17:38:42 -0000 @@ -240,6 +240,7 @@ if directive_tag == :xml a = { :version=>"1.0", :encoding=>"UTF-8" } attrs = a.merge attrs + @encoding = attrs[:encoding].downcase end _special( "2) + end + + def test_source_utf_8_target_utf_8 + @xml.foo "\xC2\xA9" + assert_equal "©\n", @xml.target! + end + + def test_source_iso_8859_1_target_utf_8 + @xml.instruct! :xml, :encoding=>'utf-8' + @xml.foo "\xA9" + assert_equal "\n©\n", @xml.target! + end + + def test_source_iso_8859_1_target_iso_8859_1 + @xml.instruct! :xml, :encoding=>'iso-8859-1' + @xml.foo "\xC2\xA9" + assert_equal "\n\302\251\n", @xml.target! + end +end