You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
2.1 KiB
56 lines
2.1 KiB
13 years ago
|
diff --git a/lib/builder/xmlbase.rb b/lib/builder/xmlbase.rb
|
||
|
index 1a1e5f9..06f8807 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.
|
||
|
@@ -132,7 +134,12 @@ module Builder
|
||
|
end
|
||
|
else
|
||
|
def _escape(text)
|
||
|
- text.to_xs((@encoding != 'utf-8' or $KCODE != 'UTF8'))
|
||
|
+ # original_xs is defined by activesupport when fast_xs is
|
||
|
+ # loaded; since fast_xs (as of version 0.8.0) does not accept
|
||
|
+ # the encode parameter, use the original function if present.
|
||
|
+ toxs_method = ::String.method_defined?(:original_xs) ? :original_xs : :to_xs
|
||
|
+
|
||
|
+ text.send(toxs_method, (@encoding != 'utf-8' or $KCODE != 'UTF8'))
|
||
|
end
|
||
|
end
|
||
|
|
||
|
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>’</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>’</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'))
|