commit 973b558e48a5af79a7239ff53f0ef2d913d8e64f
Author: Diego Elio Pettenò <flameeyes@flameeyes.eu>
Date:   Wed Jan 25 03:04:23 2012 +0100

    Fix tests with Ruby 1.9.3, where UTF-16 is a supported encoding.
    
    While the UTF-16 encoding is supported, it's a dummy encoding, so regexp
    matching is not properly implemented, so there is not much we can do but
    reject dummy encodings altogether.

diff --git a/lib/builder/xmlbase.rb b/lib/builder/xmlbase.rb
index 1a1e5f9..0c9798f 100644
--- a/lib/builder/xmlbase.rb
+++ b/lib/builder/xmlbase.rb
@@ -122,7 +122,9 @@ module Builder
       def _escape(text)
         result = XChar.encode(text)
         begin
-          result.encode(@encoding)
+          encoding = ::Encoding::find(@encoding)
+          raise Exception if encoding.dummy?
+          result.encode(encoding)
         rescue
           # if the encoding can't be supported, use numeric character references
           result.
diff --git a/test/test_markupbuilder.rb b/test/test_markupbuilder.rb
index 63864ad..2d9b853 100644
--- a/test/test_markupbuilder.rb
+++ b/test/test_markupbuilder.rb
@@ -446,13 +446,20 @@ class TestIndentedXmlMarkup < Test::Unit::TestCase
       end
     end
 
-    def test_use_entities_if_kcode_is_utf_but_encoding_is_something_else
+    def test_use_entities_if_kcode_is_utf_but_encoding_is_dummy_encoding
       xml = Builder::XmlMarkup.new
       xml.instruct!(:xml, :encoding => 'UTF-16')
       xml.p(encode("\xE2\x80\x99", 'UTF8'))
       assert_match(%r(<p>&#8217;</p>), xml.target!) #
     end
 
+    def test_use_entities_if_kcode_is_utf_but_encoding_is_unsupported_encoding
+      xml = Builder::XmlMarkup.new
+      xml.instruct!(:xml, :encoding => 'UCS-2')
+      xml.p(encode("\xE2\x80\x99", 'UTF8'))
+      assert_match(%r(<p>&#8217;</p>), xml.target!) #
+    end
+
     def test_use_utf8_if_encoding_defaults_and_kcode_is_utf8
       xml = Builder::XmlMarkup.new
       xml.p(encode("\xE2\x80\x99",'UTF8'))
