File tree 2 files changed +12
-0
lines changed
lib/active_record/connection_adapters/postgresql
2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,9 @@ def type_cast(value)
31
31
class Bytea < Type
32
32
def type_cast ( value )
33
33
return if value . nil?
34
+ # This is a flawed heuristic, but it avoids truncation;
35
+ # we really shouldn’t be calling this with already-unescaped values
36
+ return value if value =~ /\x00 /
34
37
PGconn . unescape_bytea value
35
38
end
36
39
end
Original file line number Diff line number Diff line change 4
4
require 'models/parrot'
5
5
require 'models/person' # For optimistic locking
6
6
require 'models/aircraft'
7
+ require 'models/binary'
7
8
8
9
class Pirate # Just reopening it, not defining it
9
10
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
261
262
assert_empty data . changes
262
263
end
263
264
265
+ def test_binary_with_null_byte_with_same_value_not_marked_as_changed
266
+ binary = Binary . create! ( data : "\\ \\ foo\x00 \\ \\ bar" )
267
+
268
+ binary . data = "\\ \\ foo\x00 \\ \\ bar"
269
+
270
+ assert_not binary . changed? , "should be unchanged"
271
+ end
272
+
264
273
def test_zero_to_blank_marked_as_changed
265
274
pirate = Pirate . new
266
275
pirate . catchphrase = "Yarrrr, me hearties"
You can’t perform that action at this time.
0 commit comments