Permalink
Browse files

Merge pull request #8057 from frodsan/fix_sqlite_mutate_arg

SQLite3Adapter#type_cast should not mutate arguments
  • Loading branch information...
2 parents 852e376 + b5133d0 commit 1743e9594117743a5a5dc30106cd071da672e9a6 @rafaelfranca rafaelfranca committed Oct 29, 2012
@@ -251,7 +251,7 @@ def type_cast(value, column) # :nodoc:
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
@@ -154,6 +154,12 @@ def test_quote_binary_column_escapes_it
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"

0 comments on commit 1743e95

Please sign in to comment.