Skip to content

Commit

Permalink
SQLite3Adapter#type_cast should not mutate arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Rusterholz authored and Francesco Rodriguez committed Oct 28, 2012
1 parent 852e376 commit b5133d0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Expand Up @@ -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
Expand Down
Expand Up @@ -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"
Expand Down

0 comments on commit b5133d0

Please sign in to comment.