Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

SQLite3Adapter#type_cast should not mutate arguments #8057

Merged
merged 1 commit into from

2 participants

@frodsan

I added the missing test. Related #7867.

@rafaelfranca rafaelfranca merged commit 1743e95 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 28, 2012
  1. @frodsan

    SQLite3Adapter#type_cast should not mutate arguments

    Stefan Rusterholz authored frodsan committed
This page is out of date. Refresh to see the latest.
View
2  activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
@@ -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
View
6 activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
@@ -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"
Something went wrong with that request. Please try again.