lib/em-websocket/framing07.rb in em-websocket-0.5.0 vs lib/em-websocket/framing07.rb in em-websocket-0.5.1

- old
+ new

@@ -8,11 +8,11 @@ @data = MaskedString.new @application_data_buffer = '' # Used for MORE frames @frame_type = nil end - def process_data(newdata) + def process_data error = false while !error && @data.size >= 2 pointer = 0 @@ -85,11 +85,22 @@ # Throw away data up to pointer @data.slice!(0...pointer) frame_type = opcode_to_type(opcode) - if frame_type == :continuation && !@frame_type - raise WSProtocolError, 'Continuation frame not expected' + if frame_type == :continuation + if !@frame_type + raise WSProtocolError, 'Continuation frame not expected' + end + else # Not a continuation frame + if @frame_type && data_frame?(frame_type) + raise WSProtocolError, "Continuation frame expected" + end + end + + # Validate that control frames are not fragmented + if !fin && !data_frame?(frame_type) + raise WSProtocolError, 'Control frames must not be fragmented' end if !fin debug [:moreframe, frame_type, application_data] @application_data_buffer << application_data