Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #10176: postgresql_adapter_bytea_escaping.diff

File postgresql_adapter_bytea_escaping.diff, 2.4 kB (added by tmacedo, 10 months ago)

postgresql adapter bytea escaping patch

  • activerecord/test/binary_test.rb

    old new  
    33 
    44class BinaryTest < Test::Unit::TestCase 
    55  BINARY_FIXTURE_PATH = File.dirname(__FILE__) + '/fixtures/flowers.jpg' 
     6  TEXT_FIXTURE_PATH = File.dirname(__FILE__) + '/fixtures/example.log' 
    67 
    78  def setup 
    89    Binary.connection.execute 'DELETE FROM binaries' 
    910    @data = File.read(BINARY_FIXTURE_PATH).freeze 
     11    @text = File.read(TEXT_FIXTURE_PATH).freeze 
    1012  end 
    1113   
    1214  def test_truth 
     
    3335      db_bin = Binary.find(bin.id) 
    3436      assert @data == db_bin.data, 'Reloaded data differs from original' 
    3537    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  
    3651  end 
    3752end 
  • activerecord/test/fixtures/example.log

    old new  
  • activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb

    old new  
    7575          if PGconn.respond_to?(:unescape_bytea) 
    7676            self.class.module_eval do 
    7777              define_method(:binary_to_string) do |value| 
    78                 if value =~ /\\\\\d{3}/ 
     78                if value =~ /\\\d{3}/ 
    7979                  PGconn.unescape_bytea(value) 
    8080                else 
    8181                  value 
     
    8585          else 
    8686            self.class.module_eval do 
    8787              define_method(:binary_to_string) do |value| 
    88                 if value =~ /\\\\\d{3}/ 
     88                if value =~ /\\\d{3}/ 
    8989                  result = '' 
    9090                  i, max = 0, value.size 
    9191                  while i < max