diff --git a/lib/em-websocket/connection.rb b/lib/em-websocket/connection.rb index df0c4f3..0b78c99 100644 --- a/lib/em-websocket/connection.rb +++ b/lib/em-websocket/connection.rb @@ -139,7 +139,7 @@ def process_message # If the high-order bit of the /frame type/ byte is _not_ set msg = @data.slice!(/^\x00([^\xff]*)\xff/) if msg - msg.gsub!(/^\x00|\xff$/, '') + msg.gsub!(/\A\x00|\xff\z/, '') if @state == :closing debug [:ignored_message, msg] else diff --git a/spec/integration/integration_spec.rb b/spec/integration/integration_spec.rb index 57dad8b..12b20ca 100644 --- a/spec/integration/integration_spec.rb +++ b/spec/integration/integration_spec.rb @@ -99,4 +99,30 @@ end end end + + it "should accept null bytes within the frame after a line return" do + EM.run do + EM.add_timer(0.1) do + EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 12345) { |ws| + ws.onmessage { |msg| + msg.should == "\n\000" + } + } + + # Create a fake client which sends draft 76 handshake + connection = EM.connect('0.0.0.0', 12345, FakeWebSocketClient) + connection.send_data(format_request(@request)) + + # Send closing frame after handshake complete + connection.onopen = lambda { + connection.send_data("\000\n\000\377") + connection.send_data(EM::WebSocket::Handler76::TERMINATE_STRING) + } + + connection.onclose = lambda { + EM.stop + } + end + end + end end