Skip to content

Commit

Permalink
fixup! KTOR-2588 Fix long line reading
Browse files Browse the repository at this point in the history
  • Loading branch information
e5l committed Oct 10, 2022
1 parent ae36294 commit 1555a88
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ktor-io/jvm/src/io/ktor/utils/io/ByteBufferChannel.kt
Expand Up @@ -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
}
Expand Down
14 changes: 14 additions & 0 deletions ktor-io/jvm/test/io/ktor/utils/io/charsets/ByteChannelTextTest.kt
Expand Up @@ -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())
}
}
}

0 comments on commit 1555a88

Please sign in to comment.