1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Enumerator should be supported by ActiveSupport::SafeBuffer

Back references cannot be set because C level Proc doesn't support Binding.
This commit fixes #37422.
This commit is contained in:
Shugo Maeda 2019-10-17 22:51:09 +09:00
parent 7fd5ca79a5
commit dc87302cdf
No known key found for this signature in database
GPG key ID: 2DFE34085E97CE47
2 changed files with 7 additions and 0 deletions

View file

@ -297,6 +297,8 @@ module ActiveSupport #:nodoc:
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

View file

@ -274,4 +274,9 @@ class SafeBufferTest < ActiveSupport::TestCase
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