Permalink
Browse files

Merge pull request #8057 from frodsan/fix_sqlite_mutate_arg

SQLite3Adapter#type_cast should not mutate arguments
Conflicts:
	activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
  • Loading branch information...
1 parent cdfa4a5 commit d40309a0b8faaea766f8cf89b36d2323a1d35d88 @rafaelfranca rafaelfranca committed Oct 29, 2012
@@ -205,7 +205,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
@@ -164,6 +164,14 @@ def test_quote_binary_column_escapes_it
end
end
+ def test_type_cast_should_not_mutate_encoding
+ return skip('only test encoding on 1.9') unless "<3".encoding_aware?
+
+ 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 d40309a

Please sign in to comment.