Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use force_encoding instread of encode! to avoid UndefinedConversionError #27076

Merged
merged 1 commit into from Nov 17, 2016

Conversation

y-yagi
Copy link
Member

@y-yagi y-yagi commented Nov 17, 2016

Summary

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.

"{\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 7ba3a48

Ref: #23619 (comment)

…ionError`

`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 7ba3a48

Ref: rails#23619 (comment)
@rails-bot
Copy link

r? @rafaelfranca

(@rails-bot has picked a reviewer for you, use r? to override)

@rafaelfranca
Copy link
Member

r? @sgrif

@rafaelfranca
Copy link
Member

Backported in dc9745e

rafaelfranca pushed a commit that referenced this pull request Nov 17, 2016
use `force_encoding` instread of `encode!` to avoid `UndefinedConversionError`
@y-yagi y-yagi deleted the fix_postgresql_array_encoding branch November 18, 2016 07:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants