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

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.
This commit is contained in:
Lars Kanis 2014-11-19 22:16:22 +01:00
parent b67b57d473
commit 969ef21d32
2 changed files with 9 additions and 1 deletions

View file

@ -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

View file

@ -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?