From: Martin Bosslet Date: 2011-10-19T11:08:38+09:00 Subject: [ruby-core:40219] [Ruby 1.9 - Bug #5233] OpenSSL::SSL::SSLSocket has problems with encodings other than "ascii" Issue #5233 has been updated by Martin Bosslet. > I use an "-*- encoding: binary -*-" comment at the top of all Ruby > source files where I initialize string literals for storing binary data. > It's cleaner than setting Encoding::BINARY on every string I create > (and nearly all my code works exclusively on binary data). I'm afraid this had no effect, or I did it wrong, or I might also have misunderstood you. The incoming string s already has UTF-8 encoding, so @wbuffer << s ends up as UTF-8 regardless of the encoding I set for the .rb file, I figured this was because "<<" calls rb_str_append which again calls rb_enc_check which will determine a compatible encoding, in this case UTF-8, for @wbuffer. But again, I might have misunderstood you. > Also, all of the Ruby (non-SSL) *Socket objects have Encoding::BINARY by > default anyways, so I think SSLSocket should be the same. I'm sorry, I don't understand what you mean by the *Socket objects have binary encoding by default - do you mean it's binary data they are expecting to deal with for input and output? So a user would have to make sure to only pass already BINARY-encoded strings to any *Socket? I quickly checked with a TCPServer and Net::HTTP client, there the aforementioned situation would work, when sending 100000 a-Umlauts you again receive the same amount, after enforcing the response to UTF-8 again, of course. That's why I thought that an SSLSocket should behave the same way. ---------------------------------------- Bug #5233: OpenSSL::SSL::SSLSocket has problems with encodings other than "ascii" http://redmine.ruby-lang.org/issues/5233 Author: Niklas Baumstark Status: Assigned Priority: Normal Assignee: Martin Bosslet Category: ext Target version: 1.9.4 ruby -v: ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux] The attached script shows the issue. It expects a combined cert/private key in the file server.pem under the current directory (also attached). Under Ruby 1.9.2p290, the script prints "str.size is 50848 (expecting 100000)". As a workaround the string encoding can be forced to "ascii" before the write. -- http://redmine.ruby-lang.org