Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix issue where #send would change encoding of passed string

There may well be a better way of doing this, that doesn't involve duping all strings, but this works for now
  • Loading branch information...
commit ca3e167e675b9d4200d4502b284c2286765ee2b2 1 parent 5102752
Martyn Loughran mloughran authored
4 lib/em-websocket/connection.rb
View
@@ -158,6 +158,10 @@ def send(data)
else
raise WebSocketError, "Cannot send data before onopen callback"
end
+
+ # Revert data back to the original encoding (which we assume is UTF-8)
+ # Doing this to avoid duping the string - there may be a better way
+ data.force_encoding(UTF8)
end
# Send a ping to the client. The client must respond with a pong.
18 spec/integration/shared_examples.rb
View
@@ -124,5 +124,23 @@
start_client { }
}
end
+
+ it "should not change the encoding of strings sent to send [antiregression]" do
+ em {
+ start_server { |server|
+ server.onopen {
+ s = "example string"
+ s.force_encoding("UTF-8")
+
+ server.send(s)
+
+ s.encoding.should == Encoding.find("UTF-8")
+ done
+ }
+ }
+
+ start_client { }
+ }
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.