diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-10-28 17:01:01 -0700 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-10-28 17:01:01 -0700 |
commit | 1743e9594117743a5a5dc30106cd071da672e9a6 (patch) | |
tree | 74340d4c31cba9fc36d4b0a11427f19f0855fe20 | |
parent | 852e376a5199ff700ec95d1ac916f4509f48e85e (diff) | |
parent | b5133d018fb0cd0fabc828ec028a2f081c34bcca (diff) | |
download | rails-1743e9594117743a5a5dc30106cd071da672e9a6.tar.gz rails-1743e9594117743a5a5dc30106cd071da672e9a6.tar.bz2 rails-1743e9594117743a5a5dc30106cd071da672e9a6.zip |
Merge pull request #8057 from frodsan/fix_sqlite_mutate_arg
SQLite3Adapter#type_cast should not mutate arguments
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb | 6 |
2 files changed, 7 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb index c5a859475f..b89e9a01a8 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb @@ -251,7 +251,7 @@ module ActiveRecord value = super if column.type == :string && value.encoding == Encoding::ASCII_8BIT logger.error "Binary data inserted for `string` type on column `#{column.name}`" if logger - value.encode! 'utf-8' + value = value.encode Encoding::UTF_8 end value end diff --git a/activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb b/activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb index 4e26c5dda1..559fb2435c 100644 --- a/activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb +++ b/activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb @@ -154,6 +154,12 @@ module ActiveRecord DualEncoding.connection.drop_table('dual_encodings') end + def test_type_cast_should_not_mutate_encoding + name = 'hello'.force_encoding(Encoding::ASCII_8BIT) + owner = Owner.create(name: name) + assert_equal Encoding::ASCII_8BIT, name.encoding + end + def test_execute @conn.execute "INSERT INTO items (number) VALUES (10)" records = @conn.execute "SELECT * FROM items" |