Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #4809 from cfeist/feist-sqlite-binary-corruption

Fix for SQLite binary data corrupter (to master branch)
  • Loading branch information...
commit 4ca633e4663b62653ee017e5fd02dd86f06d1200 1 parent 42dab64
Aaron Patterson tenderlove authored
17 activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
@@ -6,26 +6,11 @@ module ActiveRecord
6 6 module ConnectionAdapters #:nodoc:
7 7 class SQLiteColumn < Column #:nodoc:
8 8 class << self
9   - def string_to_binary(value)
10   - value.gsub(/\0|\%/n) do |b|
11   - case b
12   - when "\0" then "%00"
13   - when "%" then "%25"
14   - end
15   - end
16   - end
17   -
18 9 def binary_to_string(value)
19 10 if value.respond_to?(:force_encoding) && value.encoding != Encoding::ASCII_8BIT
20 11 value = value.force_encoding(Encoding::ASCII_8BIT)
21 12 end
22   -
23   - value.gsub(/%00|%25/n) do |b|
24   - case b
25   - when "%00" then "\0"
26   - when "%25" then "%"
27   - end
28   - end
  13 + value
29 14 end
30 15 end
31 16 end
1  activerecord/test/assets/test.txt
... ... @@ -0,0 +1 @@
  1 +%00
2  activerecord/test/cases/binary_test.rb
@@ -8,7 +8,7 @@
8 8 require 'models/binary'
9 9
10 10 class BinaryTest < ActiveRecord::TestCase
11   - FIXTURES = %w(flowers.jpg example.log)
  11 + FIXTURES = %w(flowers.jpg example.log test.txt)
12 12
13 13 def test_mixed_encoding
14 14 str = "\x80"

0 comments on commit 4ca633e

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