mirror of
https://github.com/github/rails.git
synced 2026-01-09 14:48:01 -05:00
Merge pull request #4809 from cfeist/feist-sqlite-binary-corruption
Fix for SQLite binary data corrupter (to master branch)
This commit is contained in:
@@ -6,26 +6,11 @@ module ActiveRecord
|
||||
module ConnectionAdapters #:nodoc:
|
||||
class SQLiteColumn < Column #:nodoc:
|
||||
class << self
|
||||
def string_to_binary(value)
|
||||
value.gsub(/\0|\%/n) do |b|
|
||||
case b
|
||||
when "\0" then "%00"
|
||||
when "%" then "%25"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def binary_to_string(value)
|
||||
if value.respond_to?(:force_encoding) && value.encoding != Encoding::ASCII_8BIT
|
||||
value = value.force_encoding(Encoding::ASCII_8BIT)
|
||||
end
|
||||
|
||||
value.gsub(/%00|%25/n) do |b|
|
||||
case b
|
||||
when "%00" then "\0"
|
||||
when "%25" then "%"
|
||||
end
|
||||
end
|
||||
value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
1
activerecord/test/assets/test.txt
Normal file
1
activerecord/test/assets/test.txt
Normal file
@@ -0,0 +1 @@
|
||||
%00
|
||||
@@ -8,7 +8,7 @@ unless current_adapter?(:SybaseAdapter, :DB2Adapter, :FirebirdAdapter)
|
||||
require 'models/binary'
|
||||
|
||||
class BinaryTest < ActiveRecord::TestCase
|
||||
FIXTURES = %w(flowers.jpg example.log)
|
||||
FIXTURES = %w(flowers.jpg example.log test.txt)
|
||||
|
||||
def test_mixed_encoding
|
||||
str = "\x80"
|
||||
|
||||
Reference in New Issue
Block a user