Skip to content
This repository
Browse code

Fixed a bug in the Ruby/MySQL that caused binary content to be escape…

…d badly and come back mangled #405 [Tobias Luetke]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@301 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 3e0077f54dc451a551360f7af9b5a9c96b3253af 1 parent 07989b6
David Heinemeier Hansson authored January 01, 2005
2  activerecord/CHANGELOG
... ...
@@ -1,5 +1,7 @@
1 1
 *SVN*
2 2
 
  3
+* Fixed a bug in the Ruby/MySQL that caused binary content to be escaped badly and come back mangled #405 [Tobias Luetke]
  4
+
3 5
 * Added block-style for callbacks #332 [bitsweat].
4 6
 
5 7
     Before:
2  activerecord/lib/active_record/vendor/mysql.rb
@@ -1091,7 +1091,7 @@ def escape_string(str)
1091 1091
       when "\0" then "\\0"
1092 1092
       when "\n" then "\\n"
1093 1093
       when "\r" then "\\r"
1094  
-      when "\032" then "\Z"
  1094
+      when "\032" then "\\Z"
1095 1095
       else "\\"+$1
1096 1096
       end
1097 1097
     end
37  activerecord/test/binary_test.rb
... ...
@@ -0,0 +1,37 @@
  1
+require 'abstract_unit'
  2
+require 'fixtures/binary'
  3
+
  4
+class BinaryTest < Test::Unit::TestCase
  5
+  def setup
  6
+    @data = create_data_fixture
  7
+  end
  8
+  
  9
+  def test_load_save
  10
+    bin = Binary.new
  11
+    bin.data = @data
  12
+
  13
+    assert bin.data == @data,
  14
+      "Assigned data differs from file data"
  15
+        
  16
+    bin.save
  17
+
  18
+    assert bin.data == @data,
  19
+      "Assigned data differs from file data after save"
  20
+
  21
+    db_bin = Binary.find(bin.id)
  22
+
  23
+    assert db_bin.data == bin.data,
  24
+      "Loaded binary data differes from memory version"
  25
+    
  26
+    assert db_bin.data == File.new(File.dirname(__FILE__)+"/fixtures/associations.png","rb").read, 
  27
+      "Loaded binary data differes from file version"
  28
+  end
  29
+  
  30
+  private
  31
+  
  32
+  def create_data_fixture
  33
+    Binary.connection.execute("DELETE FROM binaries")
  34
+    File.new(File.dirname(__FILE__)+"/fixtures/associations.png","rb").read
  35
+  end
  36
+  
  37
+end
BIN  activerecord/test/fixtures/associations.png
2  activerecord/test/fixtures/binary.rb
... ...
@@ -0,0 +1,2 @@
  1
+class Binary < ActiveRecord::Base
  2
+end
6  activerecord/test/fixtures/db_definitions/mysql.sql
@@ -115,4 +115,10 @@ CREATE TABLE `people` (
115 115
   `id` INTEGER NOT NULL PRIMARY KEY,
116 116
   `first_name` VARCHAR(40) NOT NULL,
117 117
   `lock_version` INTEGER NOT NULL DEFAULT 0
  118
+);
  119
+
  120
+CREATE TABLE `binaries` (
  121
+  `id` int(11) NOT NULL auto_increment,
  122
+  `data` mediumblob,
  123
+  PRIMARY KEY  (`id`)
118 124
 );
6  activerecord/test/fixtures/db_definitions/postgresql.sql
@@ -133,4 +133,10 @@ CREATE TABLE people (
133 133
   first_name text,
134 134
   lock_version integer default 0,
135 135
   PRIMARY KEY  (id)
  136
+);
  137
+
  138
+CREATE TABLE binaries ( 
  139
+  id serial , 
  140
+  data bytea,
  141
+  PRIMARY KEY (id)
136 142
 );
5  activerecord/test/fixtures/db_definitions/sqlite.sql
@@ -103,4 +103,9 @@ CREATE TABLE 'people' (
103 103
   'id' INTEGER NOT NULL PRIMARY KEY,
104 104
   'first_name' VARCHAR(40) DEFAULT NULL,
105 105
   'lock_version' INTEGER NOT NULL DEFAULT 0
  106
+);
  107
+
  108
+CREATE TABLE 'binaries' (
  109
+  'id' INTEGER NOT NULL PRIMARY KEY,
  110
+  'data' BLOB DEFAULT NULL
106 111
 );
11  activerecord/test/fixtures/db_definitions/sqlserver.sql
@@ -109,10 +109,17 @@ CREATE TABLE mixins (
109 109
   PRIMARY KEY (id)    
110 110
 );
111 111
 
112  
-
113 112
 CREATE TABLE people (
114 113
   id int NOT NULL IDENTITY(1, 1),
115 114
   first_name varchar(40) NULL,
116 115
   lock_version int default 0,
117 116
   PRIMARY KEY (id)
118  
-);
  117
+);
  118
+
  119
+CREATE TABLE binaries (
  120
+  id int NOT NULL IDENTITY(1, 1),
  121
+  data blob NULL,
  122
+  PRIMARY KEY (id)
  123
+);
  124
+
  125
+

0 notes on commit 3e0077f

Please sign in to comment.
Something went wrong with that request. Please try again.