From 8d1f5f6b015b3d501d03856f758d96aedc31ada0 Mon Sep 17 00:00:00 2001 From: "eric.beland@nemoves.com" Date: Fri, 13 May 2011 10:48:04 -0400 Subject: [PATCH] Fix for a Ruby 1.9.2 encoding exception: Encoding::CompatibilityError in LoggedExceptions/show. Incompatible character encodings: ASCII-8BIT and UTF-8 --- app/helpers/logged_exceptions_helper.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/helpers/logged_exceptions_helper.rb b/app/helpers/logged_exceptions_helper.rb index b8ef7f6..fa506f7 100644 --- a/app/helpers/logged_exceptions_helper.rb +++ b/app/helpers/logged_exceptions_helper.rb @@ -32,9 +32,14 @@ def page_title(text) # Rescue textilize call if RedCloth is not available. def pretty_format(text) begin - textilize(text).html_safe + txt = textilize(text).html_safe rescue - simple_format(text).html_safe + txt = simple_format(text).html_safe end + # In Ruby 1.9.x, Encoding is defined, so we force our default encoding + # to work around this Ruby 1.9 error: + # Encoding::CompatibilityError in LoggedExceptions/show + # "incompatible character encodings: ASCII-8BIT and UTF-8" + defined?(Encoding) ? txt.encode(Encoding.default_internal.to_s, undef: :replace) : txt end end