From 250be38504f8c85507b88ca385af44e825fd4835 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Wed, 31 May 2023 12:29:33 +1000 Subject: [PATCH] Revert "Return same string object when no interpolations were made" --- lib/i18n/interpolate/ruby.rb | 8 +------- test/i18n/interpolate_test.rb | 6 ------ 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/lib/i18n/interpolate/ruby.rb b/lib/i18n/interpolate/ruby.rb index 5b50593f..bfe484e8 100644 --- a/lib/i18n/interpolate/ruby.rb +++ b/lib/i18n/interpolate/ruby.rb @@ -28,11 +28,7 @@ def interpolate(string, values) def interpolate_hash(string, values) pattern = INTERPOLATION_PATTERNS_CACHE[config.interpolation_patterns] - interpolated = false - - interpolated_string = string.gsub(pattern) do |match| - interpolated = true - + string.gsub(pattern) do |match| if match == '%%' '%' else @@ -46,8 +42,6 @@ def interpolate_hash(string, values) $3 ? sprintf("%#{$3}", value) : value end end - - interpolated ? interpolated_string : string end end end diff --git a/test/i18n/interpolate_test.rb b/test/i18n/interpolate_test.rb index 2d54090f..79e59a99 100644 --- a/test/i18n/interpolate_test.rb +++ b/test/i18n/interpolate_test.rb @@ -65,15 +65,9 @@ def gsub(*args, &block) end end - test "with String subclass that redefined gsub method" do assert_equal "Hello mars world", I18n.interpolate(RailsSafeBuffer.new("Hello %{planet} world"), :planet => 'mars') end - - test "with String subclass that redefined gsub method returns same object if no interpolations" do - string = RailsSafeBuffer.new("Hello world") - assert_same string, I18n.interpolate(string, :planet => 'mars') - end end class I18nMissingInterpolationCustomHandlerTest < I18n::TestCase