From 69cc1aa5887c672881cb561d05f006527270b3cd Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Sun, 22 Feb 2009 09:12:41 +0900 Subject: [PATCH] Remove unnecessary String encoding handling --- .../vendor/i18n-0.1.1/lib/i18n/backend/simple.rb | 10 +------- .../vendor/i18n-0.1.1/test/simple_backend_test.rb | 26 +++++++++++++++++++- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/activesupport/lib/active_support/vendor/i18n-0.1.1/lib/i18n/backend/simple.rb b/activesupport/lib/active_support/vendor/i18n-0.1.1/lib/i18n/backend/simple.rb index b54164d..c09acd7 100644 --- a/activesupport/lib/active_support/vendor/i18n-0.1.1/lib/i18n/backend/simple.rb +++ b/activesupport/lib/active_support/vendor/i18n-0.1.1/lib/i18n/backend/simple.rb @@ -151,12 +151,7 @@ module I18n def interpolate(locale, string, values = {}) return string unless string.is_a?(String) - if string.respond_to?(:force_encoding) - original_encoding = string.encoding - string.force_encoding(Encoding::BINARY) - end - - result = string.gsub(MATCH) do + string.gsub(MATCH) do escaped, pattern, key = $1, $2, $2.to_sym if escaped @@ -169,9 +164,6 @@ module I18n values[key].to_s end end - - result.force_encoding(original_encoding) if original_encoding - result end # Loads a single translations file by delegating to #load_rb or diff --git a/activesupport/lib/active_support/vendor/i18n-0.1.1/test/simple_backend_test.rb b/activesupport/lib/active_support/vendor/i18n-0.1.1/test/simple_backend_test.rb index 8ba7036..cd87093 100644 --- a/activesupport/lib/active_support/vendor/i18n-0.1.1/test/simple_backend_test.rb +++ b/activesupport/lib/active_support/vendor/i18n-0.1.1/test/simple_backend_test.rb @@ -253,6 +253,30 @@ class I18nSimpleBackendInterpolateTest < Test::Unit::TestCase assert_equal 'Häi David!', @backend.send(:interpolate, nil, 'Häi {{name}}!', :name => 'David') end + def test_interpolate_given_an_unicode_value_hash_interpolates_to_the_string + assert_equal 'Hi ゆきひろ!', @backend.send(:interpolate, nil, 'Hi {{name}}!', :name => 'ゆきひろ') + end + + def test_interpolate_given_an_unicode_value_hash_interpolates_into_unicode_string + assert_equal 'こんにちは、ゆきひろさん!', @backend.send(:interpolate, nil, 'こんにちは、{{name}}さん!', :name => 'ゆきひろ') + end + + def test_interpolate_given_a_non_unicode_multibyte_value_hash_interpolates_into_a_string_with_the_same_encoding + assert_equal 'Hi ゆきひろ!'.encode!(Encoding::EUC_JP), @backend.send(:interpolate, nil, 'Hi {{name}}!', :name => 'ゆきひろ'.encode!(Encoding::EUC_JP)) + end + + def test_interpolate_given_an_unicode_value_hash_into_a_non_unicode_multibyte_string_raises_encoding_compatibility_error + assert_raises(Encoding::CompatibilityError) do + @backend.send(:interpolate, nil, 'こんにちは、{{name}}さん!'.encode!(Encoding::EUC_JP), :name => 'ゆきひろ') + end + end + + def test_interpolate_given_a_non_unicode_multibyte_value_hash_into_an_unicode_string_raises_encoding_compatibility_error + assert_raises(Encoding::CompatibilityError) do + @backend.send(:interpolate, nil, 'こんにちは、{{name}}さん!', :name => 'ゆきひろ'.encode!(Encoding::EUC_JP)) + end + end + def test_interpolate_given_nil_as_a_string_returns_nil assert_nil @backend.send(:interpolate, nil, nil, :name => 'David') end @@ -521,4 +545,4 @@ class I18nSimpleBackendReloadTranslationsTest < Test::Unit::TestCase @backend.reload! assert_equal @backend.initialized?, false end -end \ No newline at end of file +end -- 1.6.1.2