postrank-labs / goliath

Goliath is a non-blocking Ruby web server framework

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

em-websocket unicode strings cause exception (added a fix)

wolfscaptain opened this issue · comments

Trying to send unicode encoded strings through em-websocket throws an exception and closes the connection.

The problem is that the frames use an ASCII-8BIT encoded string (the default) and you can't concatenate UTF-8 encoded strings to it.

In framing07.rb (didn't bother fixing the rest, but it's identical), the problematic line is 133:

frame << application_data

A simple fix is to force Ruby to see the application data as another ASCII-8BIT encoded string, and instead of setting length (line 121 in framing07.rb) to application_data.size, set it to application_data.bytesize:

length = application_data.bytesize
...
frame << application_data.force_encoding("ASCII-8BIT")

Actually I guess this needs to be issued in the em-websocket repository.