sstephenson / hector

A private group chat server for people you trust
MIT License
131 stars 15 forks source link

Setting an 8-bit ASCII topic results in an encoding error in Ruby 1.9 #23

Closed raws closed 12 years ago

raws commented 13 years ago

Setting a topic with any character from the extended ASCII table (such as ø or ü) causes Ruby 1.9 to use its ASCII-8BIT encoding if no UTF-8 characters are present.

Sending TOPIC #channel :hørn dørn de børk, for example, results in the following error:

incompatible character encodings: UTF-8 and ASCII-8BIT
.../hector/response.rb:40:in `join'
.../hector/response.rb:40:in `to_s'
.../hector/connection.rb:42:in `respond_with'
.../hector/user_session.rb:31:in `respond_with'
.../hector/session.rb:57:in `block in broadcast_to'
.../hector/session.rb:56:in `each'
.../hector/session.rb:56:in `broadcast_to'
.../hector/channel.rb:57:in `block in broadcast'
.../hector/channel.rb:56:in `catch'
.../hector/channel.rb:56:in `broadcast'
.../hector/commands/topic.rb:10:in `on_topic'
.../hector/session.rb:126:in `receive'
.../hector/connection.rb:16:in `receive_line'

The solution is to use String#force_encoding("UTF-8"), as in 0f628d0b3e58201003754fd36ddeb3d4f01aad71. In fact, I believe addressing this at the request/response level may negate the need for the nickname- and channel-specific fixes in that commit.

raws commented 12 years ago

I'm closing this issue, since it seems to have disappeared.