Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #8057 from frodsan/fix_sqlite_mutate_arg

SQLite3Adapter#type_cast should not mutate arguments
  • Loading branch information...
commit 1743e9594117743a5a5dc30106cd071da672e9a6 2 parents 852e376 + b5133d0
Rafael Mendonça França rafaelfranca authored
2  activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
View
@@ -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
6 activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
View
@@ -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"
Please sign in to comment.
Something went wrong with that request. Please try again.