diff --git a/activesupport/lib/active_support/core_ext/string/output_safety.rb b/activesupport/lib/active_support/core_ext/string/output_safety.rb index d8e798dbc8635..b6d10484fd88e 100644 --- a/activesupport/lib/active_support/core_ext/string/output_safety.rb +++ b/activesupport/lib/active_support/core_ext/string/output_safety.rb @@ -297,6 +297,8 @@ def html_escape_interpolated_argument(arg) def set_block_back_references(block, match_data) block.binding.eval("proc { |m| $~ = m }").call(match_data) + rescue ArgumentError + # Can't create binding from C level Proc end end end diff --git a/activesupport/test/safe_buffer_test.rb b/activesupport/test/safe_buffer_test.rb index f475e05c9a1fc..9a0ac88a9264b 100644 --- a/activesupport/test/safe_buffer_test.rb +++ b/activesupport/test/safe_buffer_test.rb @@ -274,4 +274,9 @@ def test_titleize assert_equal "123foo 456bar", b assert_not_predicate b, :html_safe? end + + test "Should support Enumerator" do + a = "aaa".html_safe.gsub!(/a/).with_index { |m, i| i } + assert_equal "012", a + end end