mirror of
https://github.com/faye/websocket-driver-ruby.git
synced 2025-11-01 13:59:38 +00:00
Emit a protocol error when a closing frame has a 1-byte payload.
This commit is contained in:
@@ -355,8 +355,8 @@ module WebSocket
|
||||
@message << frame
|
||||
|
||||
when OPCODES[:close] then
|
||||
code = (bytesize >= 2) ? 256 * bytes[0] + bytes[1] : DEFAULT_ERROR_CODE
|
||||
reason = (bytesize > 2) ? Driver.encode(bytes[2..-1] || [], :utf8) : ''
|
||||
code = (bytesize >= 2) ? payload.unpack(PACK_FORMATS[2]).first : nil
|
||||
reason = (bytesize > 2) ? Driver.encode(bytes[2..-1] || [], :utf8) : nil
|
||||
|
||||
unless (bytesize == 0) or
|
||||
(code && code >= MIN_RESERVED_ERROR && code <= MAX_RESERVED_ERROR) or
|
||||
@@ -368,7 +368,7 @@ module WebSocket
|
||||
code = ERRORS[:protocol_error]
|
||||
end
|
||||
|
||||
shutdown(code, reason)
|
||||
shutdown(code || DEFAULT_ERROR_CODE, reason || '')
|
||||
|
||||
when OPCODES[:ping] then
|
||||
frame(payload, :pong)
|
||||
|
||||
@@ -563,6 +563,20 @@ describe WebSocket::Driver::Hybi do
|
||||
end
|
||||
end
|
||||
|
||||
describe "receiving a close frame with a too-short payload" do
|
||||
before do
|
||||
driver.parse [0x88, 0x01, 0x03].pack("C*")
|
||||
end
|
||||
|
||||
it "triggers the onclose event with a protocol error" do
|
||||
expect(@close).to eq [1002, ""]
|
||||
end
|
||||
|
||||
it "changes the state to :closed" do
|
||||
expect(driver.state).to eq :closed
|
||||
end
|
||||
end
|
||||
|
||||
describe "receiving a close frame with no code" do
|
||||
before do
|
||||
driver.parse [0x88, 0x00].pack("C*")
|
||||
|
||||
Reference in New Issue
Block a user