Project

General

Profile

Download (2.12 KB) Statistics
| Branch: | Tag: | Revision:
From 973b558e48a5af79a7239ff53f0ef2d913d8e64f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Diego=20Elio=20Petten=C3=B2?= <flameeyes@flameeyes.eu>
Date: Wed, 25 Jan 2012 03:04:23 +0100
Subject: [PATCH] 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.
---
lib/builder/xmlbase.rb | 4 +++-
test/test_markupbuilder.rb | 9 ++++++++-
2 files changed, 11 insertions(+), 2 deletions(-)

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'))
--
1.7.10.4

(1-1/2)