From 0dd24045a6e6a5168161b6315274c3cdb2b77966 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Fri, 18 Oct 2019 02:41:31 +0900 Subject: [PATCH] Merge pull request #37494 from shugo/safe_buffer_enumerator_fix Enumerator should be supported by ActiveSupport::SafeBuffer --- .../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 645b1fea17..62c628e23f 100644 --- a/activesupport/lib/active_support/core_ext/string/output_safety.rb +++ b/activesupport/lib/active_support/core_ext/string/output_safety.rb @@ -298,6 +298,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 f475e05c9a..9a0ac88a92 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 -- GitLab