Permalink
Browse files

Bugfix: encode text messages as UTF-8 when triggering onmessage

* The spec specifies that text messages are UTF-8, they are just handled internally as binary
* This closes #57
  • Loading branch information...
1 parent 122aef9 commit f8cb24ba7257c650f89cf3cca29ee5341419d04f @mloughran mloughran committed Aug 22, 2011
@@ -24,7 +24,12 @@ def message(message_type, extension_data, application_data)
send_frame(:pong, application_data)
when :pong
# TODO: Do something. Complete a deferrable established by a ping?
- when :text, :binary
+ when :text
+ if application_data.respond_to?(:force_encoding)
+ application_data.force_encoding("UTF-8")
+ end
+ @connection.trigger_on_message(application_data)
+ when :binary
@connection.trigger_on_message(application_data)
end
end
@@ -37,7 +37,12 @@ def message(message_type, extension_data, application_data)
send_frame(:pong, application_data)
when :pong
# TODO: Do something. Complete a deferrable established by a ping?
- when :text, :binary
+ when :text
+ if application_data.respond_to?(:force_encoding)
+ application_data.force_encoding("UTF-8")
+ end
+ @connection.trigger_on_message(application_data)
+ when :binary
@connection.trigger_on_message(application_data)
end
end
@@ -62,6 +62,7 @@ def start_client
start_server { |server|
server.onmessage { |msg|
msg.should == 'Hello'
+ msg.encoding.should == Encoding.find("UTF-8")
EM.stop
}
server.onerror {

0 comments on commit f8cb24b

Please sign in to comment.