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

Fix I18n.interpolate when ActiveSupport::SafeBuffer passed as argument #216

Merged
merged 1 commit into from
Nov 20, 2016
Merged
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
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