Permalink
Browse files

Merge pull request #8514 from mmb/filter_blob

Do not log the binding values for binary columns.
  • Loading branch information...
2 parents a8864aa + 8f59ffc commit 99d142a9375f9ba1960863b3cc745265aa9a14df @tenderlove tenderlove committed Dec 14, 2012
View
4 activerecord/CHANGELOG.md
@@ -1,5 +1,9 @@
## 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`
associations.
View
12 activerecord/lib/active_record/log_subscriber.rb
@@ -20,6 +20,16 @@ def initialize
@odd_or_even = false
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)
self.class.runtime += event.duration
return unless logger.debug?
@@ -34,7 +44,7 @@ def sql(event)
unless (payload[:binds] || []).empty?
binds = " " + payload[:binds].map { |col,v|
- [col.name, v]
+ render_bind(col, v)
}.inspect
end
View
8 activerecord/test/cases/log_subscriber_test.rb
@@ -1,4 +1,5 @@
require "cases/helper"
+require "models/binary"
require "models/developer"
require "models/post"
require "active_support/log_subscriber/test_helper"
@@ -100,4 +101,11 @@ def test_cached_queries_doesnt_log_when_level_is_not_debug
def test_initializes_runtime
Thread.new { assert_equal 0, ActiveRecord::LogSubscriber.runtime }.join
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

0 comments on commit 99d142a

Please sign in to comment.