diff options
author | yuuji.yaginuma <yuuji.yaginuma@gmail.com> | 2016-11-17 11:08:07 +0900 |
---|---|---|
committer | yuuji.yaginuma <yuuji.yaginuma@gmail.com> | 2016-11-17 11:59:03 +0900 |
commit | 70878b6e82fb33f769ab62d43c3dcf0267a3c618 (patch) | |
tree | a12201419d43102601ce29c89c9e305d362c47da /activerecord/lib/active_record/connection_adapters | |
parent | cfa5cab3a869f9c9d7525b7becead01601824f04 (diff) | |
download | rails-70878b6e82fb33f769ab62d43c3dcf0267a3c618.tar.gz rails-70878b6e82fb33f769ab62d43c3dcf0267a3c618.tar.bz2 rails-70878b6e82fb33f769ab62d43c3dcf0267a3c618.zip |
use `force_encoding` instread of `encode!` to avoid `UndefinedConversionError`
`PG::TextEncoder::Array#encode` returns the encoded value with `ASCII-8BIT`.
But in some cases, trying to convert `ASCII-8BIT` to `UTF-8` cause an error.
```ruby
"{\xE3\x83\x95\xE3\x82\xA1\xE3\x82\xA4\xE3\x83\xAB}".encode!(Encoding::UTF_8)
# => Encoding::UndefinedConversionError: "\xE3" from ASCII-8BIT to UTF-8
```
Should use `force_encoding` to avoid this error.
Follow up to 7ba3a48df5bfdc5e98506bb829f937e03b55a5b3
Ref: https://github.com/rails/rails/pull/23619#issuecomment-189924036
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/oid/array.rb | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/array.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/array.rb index b969503178..d9daaaa23e 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/oid/array.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/array.rb @@ -35,7 +35,7 @@ module ActiveRecord if value.is_a?(::Array) result = @pg_encoder.encode(type_cast_array(value, :serialize)) if encoding = determine_encoding_of_strings(value) - result.encode!(encoding) + result.force_encoding(encoding) end result else |