aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorLars Kanis <lars@greiz-reinsdorf.de>2014-11-19 22:16:22 +0100
committerLars Kanis <lars@greiz-reinsdorf.de>2014-12-29 21:26:35 +0100
commit969ef21d327ec3ada9c5c4b06c1ed92afa55dbec (patch)
treeacfa74195b13650f0bbbf4cd6186caf01e90556e /activerecord
parentb67b57d47368b4b834cfe8c58d9e26f5c819c154 (diff)
downloadrails-969ef21d327ec3ada9c5c4b06c1ed92afa55dbec.tar.gz
rails-969ef21d327ec3ada9c5c4b06c1ed92afa55dbec.tar.bz2
rails-969ef21d327ec3ada9c5c4b06c1ed92afa55dbec.zip
PostgreSQL, Fix change detection caused by wrong data for bytea unescaping.
This showed up when running BinaryTest#test_load_save with the more restrictive input string handling of pg-0.18.0.pre20141117110243.gem . Bytea values sent to the server are in binary format, but are returned back as escaped text. To fulfill the assumption that type_cast_from_database(type_cast_for_database(binary)) == binary we unescape only, if the value was really received from the server.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/oid/bytea.rb1
-rw-r--r--activerecord/test/cases/dirty_test.rb9
2 files changed, 9 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/bytea.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/bytea.rb
index 997613d7be..6bd1b8ecae 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/oid/bytea.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/bytea.rb
@@ -5,6 +5,7 @@ module ActiveRecord
class Bytea < Type::Binary # :nodoc:
def type_cast_from_database(value)
return if value.nil?
+ return value.to_s if value.is_a?(Type::Binary::Data)
PGconn.unescape_bytea(super)
end
end
diff --git a/activerecord/test/cases/dirty_test.rb b/activerecord/test/cases/dirty_test.rb
index 1eaff5e293..98cf60a8c4 100644
--- a/activerecord/test/cases/dirty_test.rb
+++ b/activerecord/test/cases/dirty_test.rb
@@ -688,7 +688,14 @@ class DirtyTest < ActiveRecord::TestCase
serialize :data
end
- klass.create!(data: "foo")
+ binary = klass.create!(data: "\\\\foo")
+
+ assert_not binary.changed?
+
+ binary.data = binary.data.dup
+
+ assert_not binary.changed?
+
binary = klass.last
assert_not binary.changed?