From dc87302cdfeb72f5c0bc19deb413a72f87f15bc3 Mon Sep 17 00:00:00 2001 From: Shugo Maeda Date: Thu, 17 Oct 2019 22:51:09 +0900 Subject: [PATCH] Enumerator should be supported by ActiveSupport::SafeBuffer Back references cannot be set because C level Proc doesn't support Binding. This commit fixes #37422. --- .../lib/active_support/core_ext/string/output_safety.rb | 2 ++ activesupport/test/safe_buffer_test.rb | 5 +++++ 2 files changed, 7 insertions(+) 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