Skip to content

Commit

Permalink
Fix handling of null bytes within a frame.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcolyer authored and igrigorik committed Jul 11, 2010
1 parent ede9793 commit 1bf4458
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/em-websocket/connection.rb
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions spec/integration/integration_spec.rb
Expand Up @@ -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

0 comments on commit 1bf4458

Please sign in to comment.