Do no unescaped already unescaped bytea values

If the unescaped value contains a null byte, pg 0.18 will raise an
exception.
上级 02edbcdf
......@@ -27,6 +27,9 @@ def type_cast(value)
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/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 @@ def test_float_zero_to_string_zero_not_marked_as_changed
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"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册