mirror of https://github.com/rails/rails
Do no unescaped already unescaped bytea values
If the unescaped value contains a null byte, pg 0.18 will raise an exception.
This commit is contained in:
parent
02edbcdf22
commit
ed2b4eb1cb
|
@ -27,6 +27,9 @@ module ActiveRecord
|
|||
class Bytea < Type
|
||||
def type_cast(value)
|
||||
return if value.nil?
|
||||
# This is a flawed heuristic, but it avoids truncation;
|
||||
# we really shouldn’t be calling this with already-unescaped values
|
||||
return value if value =~ /\x00/
|
||||
PGconn.unescape_bytea value
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,6 +4,7 @@ require 'models/pirate' # For timestamps
|
|||
require 'models/parrot'
|
||||
require 'models/person' # For optimistic locking
|
||||
require 'models/aircraft'
|
||||
require 'models/binary'
|
||||
|
||||
class Pirate # Just reopening it, not defining it
|
||||
attr_accessor :detected_changes_in_after_update # Boolean for if changes are detected
|
||||
|
@ -261,6 +262,14 @@ class DirtyTest < ActiveRecord::TestCase
|
|||
assert_empty data.changes
|
||||
end
|
||||
|
||||
def test_binary_with_null_byte_with_same_value_not_marked_as_changed
|
||||
binary = Binary.create!(data: "\\\\foo\x00\\\\bar")
|
||||
|
||||
binary.data = "\\\\foo\x00\\\\bar"
|
||||
|
||||
assert_not binary.changed?, "should be unchanged"
|
||||
end
|
||||
|
||||
def test_zero_to_blank_marked_as_changed
|
||||
pirate = Pirate.new
|
||||
pirate.catchphrase = "Yarrrr, me hearties"
|
||||
|
|
Loading…
Reference in New Issue