From dc5c155761643e1c286617e7e6bd0ae468715c67 Mon Sep 17 00:00:00 2001 From: Konstantin Aleev Date: Tue, 29 Apr 2025 14:09:03 +0200 Subject: [PATCH] Skip empty lines (#89) --- .../modelcontextprotocol/kotlin/sdk/shared/ReadBuffer.kt | 2 +- src/jvmTest/kotlin/shared/ReadBufferTest.kt | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/shared/ReadBuffer.kt b/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/shared/ReadBuffer.kt index 639f5be..c901ed2 100644 --- a/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/shared/ReadBuffer.kt +++ b/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/shared/ReadBuffer.kt @@ -24,7 +24,7 @@ public class ReadBuffer { -1L -> return null 0L -> { buffer.skip(1) - "" + return null } else -> { diff --git a/src/jvmTest/kotlin/shared/ReadBufferTest.kt b/src/jvmTest/kotlin/shared/ReadBufferTest.kt index 23dcd3f..850e2ef 100644 --- a/src/jvmTest/kotlin/shared/ReadBufferTest.kt +++ b/src/jvmTest/kotlin/shared/ReadBufferTest.kt @@ -41,6 +41,13 @@ class ReadBufferTest { assertNull(readBuffer.readMessage()) } + @Test + fun `skip empty line`() { + val readBuffer = ReadBuffer() + readBuffer.append("\n".toByteArray(StandardCharsets.UTF_8)) + assertNull(readBuffer.readMessage()) + } + @Test fun `should be reusable after clearing`() { val readBuffer = ReadBuffer()