Skip to content

Commit 0db22c7

Browse files
authored
Fix Response not appending trailing slash to collections (#130)
* Fix empty filterIsInstance in Ktor and OkHttp responses - Change `map` to `flatMap` for properties in both Ktor and OkHttp response handling - Ensure `filterIsInstance<ResourceType>` works correctly by flattening the properties list * Fix tests
1 parent bcb3002 commit 0db22c7

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

src/main/kotlin/at/bitfire/dav4jvm/ktor/Response.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ data class Response(
180180
// if we know this resource is a collection, make sure href has a trailing slash
181181
// (for clarity and resolving relative paths)
182182
propStat.filter { it.status.isSuccess() }
183-
.map { it.properties }
183+
.flatMap { it.properties }
184184
.filterIsInstance<ResourceType>()
185185
.firstOrNull()
186186
?.let { type ->

src/main/kotlin/at/bitfire/dav4jvm/okhttp/Response.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ data class Response(
176176
// if we know this resource is a collection, make sure href has a trailing slash
177177
// (for clarity and resolving relative paths)
178178
propStat.filter { it.isSuccess() }
179-
.map { it.properties }
179+
.flatMap { it.properties }
180180
.filterIsInstance<ResourceType>()
181181
.firstOrNull()
182182
?.let { type ->

src/test/kotlin/at/bitfire/dav4jvm/ktor/DavResourceTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ class DavResourceTest {
924924
}
925925
}
926926
}
927-
assertEquals(4, nrCalled)
927+
assertEquals(5, nrCalled)
928928
}
929929

930930
@Test

src/test/kotlin/at/bitfire/dav4jvm/okhttp/DavResourceTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ class DavResourceTest {
848848
}
849849
}
850850
}
851-
assertEquals(4, nrCalled)
851+
assertEquals(5, nrCalled)
852852

853853

854854
/*** SPECIAL CASES ***/

0 commit comments

Comments
 (0)