rails/rails — Issue #4616: ActiveResource 3.1 Non-ASCII Encoding Bug
Author: cjolly
Created: 2012-01-23 15:32:12+00:00
State: open

To reproduce:
Rails ~> 3.1.3
Ruby 1.9.2p.290
ActiveResource::Base.format = :xml
ActiveResource::Base.site set to an https uri.

````
class Post < ActiveResource::Base
self.site = 'https://secureapi.example.com'
self.format = :xml
end

post = Post.find(1)
post.title = "Café!"
post.save
... ActiveResource::TimeoutError
````

[Ruby 1.9.2p.290 has an OpenSSL::Buffering bug](http://bugs.ruby-lang.org/issues/5233) that affects active resource with ssl sites.

In Rails, JSON appears to be unaffected as it already [forces binary encoding](https://github.com/rails/rails/blob/31472ba6328e1be5f7390840d00e67862510c2e2/activesupport/lib/active_support/json/encoding.rb#L121) in it's `encode` method.

I believe a well placed `.force_encoding(::Encoding::BINARY)` in the to_xml chain would fix the issue. I'm not too familiar with the XMLMini code and had trouble finding a place to focus my efforts. I am more than willing to tackle the issue with a little direction, but wanted to get the issue into the open first.

For the time being, here's a [workaround](https://gist.github.com/1663722) I'm using in a production app hosted on Heroku cedar.