Permalink
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...
1 parent 5102752 commit ca3e167e675b9d4200d4502b284c2286765ee2b2 @mloughran mloughran committed Jun 8, 2012
Showing with 22 additions and 0 deletions.
  1. +4 −0 lib/em-websocket/connection.rb
  2. +18 −0 spec/integration/shared_examples.rb
View
4 lib/em-websocket/connection.rb
@@ -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.
View
18 spec/integration/shared_examples.rb
@@ -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

0 comments on commit ca3e167

Please sign in to comment.