Skip to content

Commit

Permalink
Bugfix: encode text messages as UTF-8 when triggering onmessage
Browse files Browse the repository at this point in the history
* The spec specifies that text messages are UTF-8, they are just handled internally as binary
* This closes igrigorik#57
  • Loading branch information
mloughran committed Aug 22, 2011
1 parent 122aef9 commit f8cb24b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/em-websocket/message_processor_03.rb
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion lib/em-websocket/message_processor_06.rb
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions spec/integration/draft06_spec.rb
Expand Up @@ -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 {
Expand Down

0 comments on commit f8cb24b

Please sign in to comment.