diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-11-22 01:29:19 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-11-22 01:29:19 +0000 |
commit | dd27c4e5fb338e2571e691c23b39cdd857eca7cd (patch) | |
tree | 96554cde217963c6e2c76664ef010303ba6e9d6e /activerecord | |
parent | ec93d61fb9a571aeb714ddc9bd594510485f5b7f (diff) | |
download | rails-dd27c4e5fb338e2571e691c23b39cdd857eca7cd.tar.gz rails-dd27c4e5fb338e2571e691c23b39cdd857eca7cd.tar.bz2 rails-dd27c4e5fb338e2571e691c23b39cdd857eca7cd.zip |
PostgreSQL: correct binary escaping. References #8049, closes #10176 [jbasdf, tmacedo]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8185 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb | 4 | ||||
-rw-r--r-- | activerecord/test/binary_test.rb | 49 |
2 files changed, 24 insertions, 29 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 64f314a7f6..b5b636d1a4 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -75,7 +75,7 @@ module ActiveRecord if PGconn.respond_to?(:unescape_bytea) self.class.module_eval do define_method(:binary_to_string) do |value| - if value =~ /\\\\\d{3}/ + if value =~ /\\\d{3}/ PGconn.unescape_bytea(value) else value @@ -85,7 +85,7 @@ module ActiveRecord else self.class.module_eval do define_method(:binary_to_string) do |value| - if value =~ /\\\\\d{3}/ + if value =~ /\\\d{3}/ result = '' i, max = 0, value.size while i < max diff --git a/activerecord/test/binary_test.rb b/activerecord/test/binary_test.rb index 3e35f1754f..6ab272fe25 100644 --- a/activerecord/test/binary_test.rb +++ b/activerecord/test/binary_test.rb @@ -1,37 +1,32 @@ require 'abstract_unit' -require 'fixtures/binary' -class BinaryTest < Test::Unit::TestCase - BINARY_FIXTURE_PATH = File.dirname(__FILE__) + '/fixtures/flowers.jpg' +# Without using prepared statements, it makes no sense to test +# BLOB data with SQL Server, because the length of a statement is +# limited to 8KB. +# +# Without using prepared statements, it makes no sense to test +# BLOB data with DB2 or Firebird, because the length of a statement +# is limited to 32KB. +unless current_adapter?(:SQLServerAdapter, :SybaseAdapter, :DB2Adapter, :FirebirdAdapter) + require 'fixtures/binary' - def setup - Binary.connection.execute 'DELETE FROM binaries' - @data = File.read(BINARY_FIXTURE_PATH).freeze - end - - def test_truth - assert true - end + class BinaryTest < Test::Unit::TestCase + FIXTURES = %w(flowers.jpg example.log) - # Without using prepared statements, it makes no sense to test - # BLOB data with SQL Server, because the length of a statement is - # limited to 8KB. - # - # Without using prepared statements, it makes no sense to test - # BLOB data with DB2 or Firebird, because the length of a statement - # is limited to 32KB. - unless current_adapter?(:SQLServerAdapter, :SybaseAdapter, :DB2Adapter, :FirebirdAdapter) def test_load_save - bin = Binary.new - bin.data = @data + Binary.delete_all + + FIXTURES.each do |filename| + data = File.read("#{File.dirname(__FILE__)}/fixtures/#{filename}").freeze + + bin = Binary.new(:data => data) + assert_equal data, bin.data, 'Newly assigned data differs from original' - assert @data == bin.data, 'Newly assigned data differs from original' - - bin.save - assert @data == bin.data, 'Data differs from original after save' + bin.save! + assert_equal data, bin.data, 'Data differs from original after save' - db_bin = Binary.find(bin.id) - assert @data == db_bin.data, 'Reloaded data differs from original' + assert_equal data, bin.reload.data, 'Reloaded data differs from original' + end end end end |