提交 b5133d01 编写于 作者: S Stefan Rusterholz 提交者: Francesco Rodriguez

SQLite3Adapter#type_cast should not mutate arguments

上级 852e376a
......@@ -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"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册