Skip to content

Commit

Permalink
KTOR-7625: Url.segments parsing fix
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-erofeev authored and bjhham committed Oct 28, 2024
1 parent 95426ce commit 451f664
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ktor-http/common/src/io/ktor/http/Url.kt
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public class Url internal constructor(
**/
public val segments: List<String> by lazy {
if (pathSegments.isEmpty()) return@lazy emptyList()
val start = if (pathSegments.first().isEmpty()) 1 else 0
val start = if (pathSegments.first().isEmpty() && pathSegments.size > 1) 1 else 0
val end = if (pathSegments.last().isEmpty()) pathSegments.lastIndex else pathSegments.lastIndex + 1
pathSegments.subList(start, end)
}
Expand Down
3 changes: 3 additions & 0 deletions ktor-http/common/test/io/ktor/tests/http/UrlTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class UrlTest {
val relative = Url("docs")
val relativeWithTrailing = Url("docs/")
val empty = Url("https://ktor.io")
val emptyWithTrailing = Url("http://ktor.io/")


val expected = listOf("docs")
assertContentEquals(expected, full.segments)
Expand All @@ -42,6 +44,7 @@ class UrlTest {
assertContentEquals(expected, relative.segments)
assertContentEquals(expected, relativeWithTrailing.segments)
assertContentEquals(emptyList<String>(), empty.segments)
assertContentEquals(emptyList(), emptyWithTrailing.segments)
}

@Test
Expand Down

0 comments on commit 451f664

Please sign in to comment.