Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Return same string object when no interpolations were made" #660

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions lib/i18n/interpolate/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -46,8 +42,6 @@ def interpolate_hash(string, values)
$3 ? sprintf("%#{$3}", value) : value
end
end

interpolated ? interpolated_string : string
end
end
end
6 changes: 0 additions & 6 deletions test/i18n/interpolate_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down