diff --git a/ktor-io/jvm/src/io/ktor/utils/io/ByteBufferChannel.kt b/ktor-io/jvm/src/io/ktor/utils/io/ByteBufferChannel.kt index 27239eb5e1..f0eb60c8f2 100644 --- a/ktor-io/jvm/src/io/ktor/utils/io/ByteBufferChannel.kt +++ b/ktor-io/jvm/src/io/ktor/utils/io/ByteBufferChannel.kt @@ -1962,12 +1962,12 @@ internal open class ByteBufferChannel( newLine = true } - if (it.hasRemaining() && it[it.position()] == '\r'.code.toByte()) { + if (requiredBytes != -1 && it.hasRemaining() && it[it.position()] == '\r'.code.toByte()) { it.position(it.position() + 1) caret = true } - if (it.hasRemaining() && it[it.position()] == '\n'.code.toByte()) { + if (requiredBytes != -1 && it.hasRemaining() && it[it.position()] == '\n'.code.toByte()) { it.position(it.position() + 1) newLine = true } diff --git a/ktor-io/jvm/test/io/ktor/utils/io/charsets/ByteChannelTextTest.kt b/ktor-io/jvm/test/io/ktor/utils/io/charsets/ByteChannelTextTest.kt index fc7bcee1c3..1158a6c45c 100644 --- a/ktor-io/jvm/test/io/ktor/utils/io/charsets/ByteChannelTextTest.kt +++ b/ktor-io/jvm/test/io/ktor/utils/io/charsets/ByteChannelTextTest.kt @@ -42,4 +42,18 @@ class ByteChannelTextTest { val result = channel.readUTF8Line() assertEquals(line, result) } + + @Test + fun test2EmptyLines() { + val text = ByteReadChannel("\r\n\r\n") + + runBlocking { + assertEquals(4, text.availableForRead) + assertEquals("", text.readUTF8Line()) + assertEquals(2, text.availableForRead) + assertEquals(2, text.totalBytesRead) + assertEquals("", text.readUTF8Line()) + assertNull(text.readUTF8Line()) + } + } }