Skip to content

Commit

Permalink
Fix I18n.interpolate when ActiveSupport::SafeBuffer passed as argument
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan committed Aug 31, 2013
1 parent 3e53950 commit 913e40e
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 @@ -58,6 +58,17 @@ class I18nInterpolateTest < Test::Unit::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 < Test::Unit::TestCase
Expand Down

0 comments on commit 913e40e

Please sign in to comment.