Ticket #10176: postgresql_adapter_bytea_escaping.diff
| File postgresql_adapter_bytea_escaping.diff, 2.4 kB (added by tmacedo, 10 months ago) |
|---|
-
activerecord/test/binary_test.rb
old new 3 3 4 4 class BinaryTest < Test::Unit::TestCase 5 5 BINARY_FIXTURE_PATH = File.dirname(__FILE__) + '/fixtures/flowers.jpg' 6 TEXT_FIXTURE_PATH = File.dirname(__FILE__) + '/fixtures/example.log' 6 7 7 8 def setup 8 9 Binary.connection.execute 'DELETE FROM binaries' 9 10 @data = File.read(BINARY_FIXTURE_PATH).freeze 11 @text = File.read(TEXT_FIXTURE_PATH).freeze 10 12 end 11 13 12 14 def test_truth … … 33 35 db_bin = Binary.find(bin.id) 34 36 assert @data == db_bin.data, 'Reloaded data differs from original' 35 37 end 38 39 def test_text_load_save 40 bin = Binary.new 41 bin.data = @text 42 43 assert @text == bin.data, 'Newly assigned data differs from original' 44 45 bin.save 46 assert @text == bin.data, 'Data differs from original after save' 47 48 db_bin = Binary.find(bin.id) 49 assert @text == db_bin.data, 'Reloaded data differs from original' 50 end 36 51 end 37 52 end -
activerecord/test/fixtures/example.log
old new -
activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
old new 75 75 if PGconn.respond_to?(:unescape_bytea) 76 76 self.class.module_eval do 77 77 define_method(:binary_to_string) do |value| 78 if value =~ /\\\ \\d{3}/78 if value =~ /\\\d{3}/ 79 79 PGconn.unescape_bytea(value) 80 80 else 81 81 value … … 85 85 else 86 86 self.class.module_eval do 87 87 define_method(:binary_to_string) do |value| 88 if value =~ /\\\ \\d{3}/88 if value =~ /\\\d{3}/ 89 89 result = '' 90 90 i, max = 0, value.size 91 91 while i < max