Fixed a bug in the Ruby/MySQL that caused binary content to be escaped badly...

Fixed a bug in the Ruby/MySQL that caused binary content to be escaped badly and come back mangled #405 [Tobias Luetke]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@301 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 07989b64
*SVN*
* Fixed a bug in the Ruby/MySQL that caused binary content to be escaped badly and come back mangled #405 [Tobias Luetke]
* Added block-style for callbacks #332 [bitsweat].
Before:
......
......@@ -1091,7 +1091,7 @@ def escape_string(str)
when "\0" then "\\0"
when "\n" then "\\n"
when "\r" then "\\r"
when "\032" then "\Z"
when "\032" then "\\Z"
else "\\"+$1
end
end
......
require 'abstract_unit'
require 'fixtures/binary'
class BinaryTest < Test::Unit::TestCase
def setup
@data = create_data_fixture
end
def test_load_save
bin = Binary.new
bin.data = @data
assert bin.data == @data,
"Assigned data differs from file data"
bin.save
assert bin.data == @data,
"Assigned data differs from file data after save"
db_bin = Binary.find(bin.id)
assert db_bin.data == bin.data,
"Loaded binary data differes from memory version"
assert db_bin.data == File.new(File.dirname(__FILE__)+"/fixtures/associations.png","rb").read,
"Loaded binary data differes from file version"
end
private
def create_data_fixture
Binary.connection.execute("DELETE FROM binaries")
File.new(File.dirname(__FILE__)+"/fixtures/associations.png","rb").read
end
end
\ No newline at end of file
class Binary < ActiveRecord::Base
end
\ No newline at end of file
......@@ -115,4 +115,10 @@ CREATE TABLE `people` (
`id` INTEGER NOT NULL PRIMARY KEY,
`first_name` VARCHAR(40) NOT NULL,
`lock_version` INTEGER NOT NULL DEFAULT 0
);
CREATE TABLE `binaries` (
`id` int(11) NOT NULL auto_increment,
`data` mediumblob,
PRIMARY KEY (`id`)
);
\ No newline at end of file
......@@ -133,4 +133,10 @@ CREATE TABLE people (
first_name text,
lock_version integer default 0,
PRIMARY KEY (id)
);
CREATE TABLE binaries (
id serial ,
data bytea,
PRIMARY KEY (id)
);
\ No newline at end of file
......@@ -103,4 +103,9 @@ CREATE TABLE 'people' (
'id' INTEGER NOT NULL PRIMARY KEY,
'first_name' VARCHAR(40) DEFAULT NULL,
'lock_version' INTEGER NOT NULL DEFAULT 0
);
CREATE TABLE 'binaries' (
'id' INTEGER NOT NULL PRIMARY KEY,
'data' BLOB DEFAULT NULL
);
\ No newline at end of file
......@@ -109,10 +109,17 @@ CREATE TABLE mixins (
PRIMARY KEY (id)
);
CREATE TABLE people (
id int NOT NULL IDENTITY(1, 1),
first_name varchar(40) NULL,
lock_version int default 0,
PRIMARY KEY (id)
);
\ No newline at end of file
);
CREATE TABLE binaries (
id int NOT NULL IDENTITY(1, 1),
data blob NULL,
PRIMARY KEY (id)
);
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册