Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit f8cb24ba7257c650f89cf3cca29ee5341419d04f 1 parent 122aef9
@mloughran mloughran authored
View
7 lib/em-websocket/message_processor_03.rb
@@ -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
View
7 lib/em-websocket/message_processor_06.rb
@@ -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
View
1  spec/integration/draft06_spec.rb
@@ -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 {
Please sign in to comment.
Something went wrong with that request. Please try again.