diff --git a/lib/server/client_stream_processor.js b/lib/server/client_stream_processor.js index 5849f1f..2ea4a40 100644 --- a/lib/server/client_stream_processor.js +++ b/lib/server/client_stream_processor.js @@ -122,7 +122,7 @@ class ClientStreamProcessor extends Transform { if(!fillBufferWithData()) { // Quit? - if (data[data.length - 1] === CMD_QUIT) { + if (!readState.didParseCmd && data[data.length - 1] === CMD_QUIT) { this.push('q'); } diff --git a/test/protocol.js b/test/protocol.js index d706f9e..db15309 100644 --- a/test/protocol.js +++ b/test/protocol.js @@ -153,6 +153,11 @@ describe("Protocol", () => { tests.forEach(function (test) { it(`should store ${test.ext} data with a (${test.cmd}) command (client write packet size = ${test.packetSize})`, () => { + // Insert 'q' character ('Quit' command) into the GUID, to catch subtle protocol errors when packet size is 1 + if(test.packetSize === 1) { + test.data.guid[0] = test.data.guid[test.data.guid.length - 1] = 'q'.charCodeAt(0); + } + const buf = Buffer.from( encodeCommand(cmd.transactionStart, test.data.guid, test.data.hash) + encodeCommand(test.cmd, null, null, test.data[test.ext]) +