aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Rusterholz <contact@apeiros.me>2012-10-28 18:55:36 -0500
committerFrancesco Rodriguez <lrodriguezsanc@gmail.com>2012-10-28 18:55:36 -0500
commitb5133d018fb0cd0fabc828ec028a2f081c34bcca (patch)
tree74340d4c31cba9fc36d4b0a11427f19f0855fe20
parent852e376a5199ff700ec95d1ac916f4509f48e85e (diff)
downloadrails-b5133d018fb0cd0fabc828ec028a2f081c34bcca.tar.gz
rails-b5133d018fb0cd0fabc828ec028a2f081c34bcca.tar.bz2
rails-b5133d018fb0cd0fabc828ec028a2f081c34bcca.zip
SQLite3Adapter#type_cast should not mutate arguments
-rw-r--r--activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb2
-rw-r--r--activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb6
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"