Skip to content

Commit

Permalink
Merge pull request #216 from bogdan/interpolate-rails-safe-buffer
Browse files Browse the repository at this point in the history
Fix I18n.interpolate when ActiveSupport::SafeBuffer passed as argument
  • Loading branch information
radar committed Nov 20, 2016
2 parents 1bcc77b + 913e40e commit e532e61
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/i18n/interpolate/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def interpolate_hash(string, values)
if match == '%%'
'%'
else
key = ($1 || $2).to_sym
key = ($1 || $2 || match.tr("%{}", "")).to_sym
value = if values.key?(key)
values[key]
else
Expand Down
11 changes: 11 additions & 0 deletions test/i18n/interpolate_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ class I18nInterpolateTest < I18n::TestCase
def test_sprintf_mix_unformatted_and_formatted_named_placeholders
assert_equal "foo 1.000000", I18n.interpolate("%{name} %<num>f", :name => "foo", :num => 1.0)
end

class RailsSafeBuffer < String

def gsub(*args, &block)
to_str.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
end

class I18nMissingInterpolationCustomHandlerTest < I18n::TestCase
Expand Down

0 comments on commit e532e61

Please sign in to comment.