safe buffer back reference

TIL back references for sub, sub!, gsub, and gsub! are finally fixed for ActiveSupport::SafeBuffer through the use of block.binding.eval.

The behaviour being fixed is:

"foo123".html_safe.sub(/([a-z]+)([0-9]+)/) {
  $2 + $1 #=> NoMethodError: undefined method `+' for nil:NilClass
}

If this is confusing I recommend the following resource: Bindings in Ruby – Behind the Magic of Blocks