From 66e18585eca8d17ed8346b6ed0eee6938d1d6cff Mon Sep 17 00:00:00 2001 From: James S. Ravn Date: Tue, 13 Jan 2009 11:41:29 -0600 Subject: [PATCH] Correctly handle unsupported iconv libraries. * The Iconv library raises an exception on Solaris, AIX, and other platforms when ActiveSupport::Inflector.transliterate is defined. This fix rescues from the exception so that the native transliterate method can be defined. --- activesupport/lib/active_support/inflector.rb | 1 + activesupport/test/inflector_test.rb | 5 +++++ 2 files changed, 6 insertions(+), 0 deletions(-) diff --git a/activesupport/lib/active_support/inflector.rb b/activesupport/lib/active_support/inflector.rb index 4921b99..4230c27 100644 --- a/activesupport/lib/active_support/inflector.rb +++ b/activesupport/lib/active_support/inflector.rb @@ -273,6 +273,7 @@ module ActiveSupport # Replaces accented characters with their ascii equivalents. def transliterate(string) Iconv.iconv('ascii//ignore//translit', 'utf-8', string).to_s + rescue Iconv::InvalidEncoding end if RUBY_VERSION >= '1.9' diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb index d8c93dc..b525fb9 100644 --- a/activesupport/test/inflector_test.rb +++ b/activesupport/test/inflector_test.rb @@ -104,6 +104,11 @@ class InflectorTest < Test::Unit::TestCase end end + def test_unsupported_iconv + Iconv.stubs(:iconv).raises(Iconv::InvalidEncoding.allocate) + assert_nothing_raised { load 'active_support/inflector.rb' } + end + def test_parameterize_and_normalize StringToParameterizedAndNormalized.each do |some_string, parameterized_string| assert_equal(parameterized_string, ActiveSupport::Inflector.parameterize(some_string)) -- 1.6.0.5