提交 99d142a9 编写于 作者: A Aaron Patterson

Merge pull request #8514 from mmb/filter_blob

Do not log the binding values for binary columns.
## Rails 4.0.0 (unreleased) ## ## Rails 4.0.0 (unreleased) ##
* Do not log the binding values for binary columns.
*Matthew M. Boedicker*
* Fix counter cache columns not updated when replacing `has_many :through` * Fix counter cache columns not updated when replacing `has_many :through`
associations. associations.
......
...@@ -20,6 +20,16 @@ def initialize ...@@ -20,6 +20,16 @@ def initialize
@odd_or_even = false @odd_or_even = false
end end
def render_bind(column, value)
if column.type == :binary
rendered_value = "<#{value.bytesize} bytes of binary data>"
else
rendered_value = value
end
[column.name, rendered_value]
end
def sql(event) def sql(event)
self.class.runtime += event.duration self.class.runtime += event.duration
return unless logger.debug? return unless logger.debug?
...@@ -34,7 +44,7 @@ def sql(event) ...@@ -34,7 +44,7 @@ def sql(event)
unless (payload[:binds] || []).empty? unless (payload[:binds] || []).empty?
binds = " " + payload[:binds].map { |col,v| binds = " " + payload[:binds].map { |col,v|
[col.name, v] render_bind(col, v)
}.inspect }.inspect
end end
......
require "cases/helper" require "cases/helper"
require "models/binary"
require "models/developer" require "models/developer"
require "models/post" require "models/post"
require "active_support/log_subscriber/test_helper" require "active_support/log_subscriber/test_helper"
...@@ -100,4 +101,11 @@ def test_cached_queries_doesnt_log_when_level_is_not_debug ...@@ -100,4 +101,11 @@ def test_cached_queries_doesnt_log_when_level_is_not_debug
def test_initializes_runtime def test_initializes_runtime
Thread.new { assert_equal 0, ActiveRecord::LogSubscriber.runtime }.join Thread.new { assert_equal 0, ActiveRecord::LogSubscriber.runtime }.join
end end
def test_binary_data_is_not_logged
Binary.create(:data => 'some binary data')
wait
assert_equal 3, @logger.logged(:debug).size
assert_match(/<16 bytes of binary data>/, @logger.logged(:debug)[-2])
end
end end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册