diff options
author | Sean Griffin <sean@thoughtbot.com> | 2015-01-28 15:17:17 -0700 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2015-01-28 15:19:13 -0700 |
commit | 96ac14a3856b9e48e11c7f1e0552ef2f3a87e4d6 (patch) | |
tree | 95c7e1d0e0547a9b719c53edadc8ee51474e9c31 /activerecord | |
parent | 82173989de711ecda71b7e887291a524c23c14ce (diff) | |
download | rails-96ac14a3856b9e48e11c7f1e0552ef2f3a87e4d6.tar.gz rails-96ac14a3856b9e48e11c7f1e0552ef2f3a87e4d6.tar.bz2 rails-96ac14a3856b9e48e11c7f1e0552ef2f3a87e4d6.zip |
Always convert strings to UTF-8, regardless of column type in SQLite
All columns which would map to a string primitive need this behavior.
Binary has it's own marker type, so it won't go through this conversion.
String and text, which need this, will.
Fixes #18585.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb | 17 | ||||
-rw-r--r-- | activerecord/test/cases/adapters/sqlite3/quoting_test.rb | 2 |
2 files changed, 7 insertions, 12 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb index 225c2a8587..02a3b65934 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb @@ -50,16 +50,6 @@ module ActiveRecord end end - class SQLite3String < Type::String # :nodoc: - def type_cast_for_database(value) - if value.is_a?(::String) && value.encoding == Encoding::ASCII_8BIT - value.encode(Encoding::UTF_8, undef: :replace) - else - super - end - end - end - # The SQLite3 adapter works SQLite 3.6.16 or newer # with the sqlite3-ruby drivers (available as gem from https://rubygems.org/gems/sqlite3). # @@ -239,6 +229,12 @@ module ActiveRecord case value when BigDecimal value.to_f + when String + if value.encoding == Encoding::ASCII_8BIT + super(value.encode(Encoding::UTF_8)) + else + super + end else super end @@ -496,7 +492,6 @@ module ActiveRecord def initialize_type_map(m) super m.register_type(/binary/i, SQLite3Binary.new) - register_class_with_limit m, %r(char)i, SQLite3String end def table_structure(table_name) diff --git a/activerecord/test/cases/adapters/sqlite3/quoting_test.rb b/activerecord/test/cases/adapters/sqlite3/quoting_test.rb index 274e358e4a..c1d9b7c273 100644 --- a/activerecord/test/cases/adapters/sqlite3/quoting_test.rb +++ b/activerecord/test/cases/adapters/sqlite3/quoting_test.rb @@ -85,7 +85,7 @@ module ActiveRecord def test_quoting_binary_strings value = "hello".encode('ascii-8bit') - type = SQLite3String.new + type = Type::String.new assert_equal "'hello'", @conn.quote(type.type_cast_for_database(value)) end |