Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,11 @@ private fun ApplicationCall.extractDeleteChannelUrl(): String? {
if (rawTail.isBlank()) return null
return runCatching { URLDecoder.decode(rawTail, StandardCharsets.UTF_8) }
.getOrDefault(rawTail)
.restoreCollapsedScheme()
.takeIf { it.isNotBlank() }
}

private fun String.restoreCollapsedScheme(): String {
val match = Regex("^([A-Za-z][A-Za-z0-9+.-]*):/([^/].*)$").matchEntire(this) ?: return this
return "${match.groupValues[1]}://${match.groupValues[2]}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ class SubscriptionsDeleteProxyRoutesTest {
}

@Test
fun `DELETE subscriptions uses query url when path is proxy-decoded`() = withApp {
fun `DELETE subscriptions repairs proxy-decoded path`() = withApp {
service.add(TEST_USER_ID, SubscriptionItem(channelUrl = "https://www.youtube.com/channel/UC123", name = "T", avatarUrl = ""))
val response = client.delete("/subscriptions/https:/www.youtube.com/channel/UC123?url=https%3A%2F%2Fwww.youtube.com%2Fchannel%2FUC123") {
val response = client.delete("/subscriptions/https:/www.youtube.com/channel/UC123") {
headers.append(HttpHeaders.Authorization, "Bearer test-jwt")
}
assertEquals(HttpStatusCode.NoContent, response.status)
Expand All @@ -72,4 +72,13 @@ class SubscriptionsDeleteProxyRoutesTest {
}.bodyAsText()
assertFalse(body.contains("UC123"))
}

@Test
fun `DELETE subscriptions accepts query url when provided`() = withApp {
service.add(TEST_USER_ID, SubscriptionItem(channelUrl = "https://www.youtube.com/channel/UC123", name = "T", avatarUrl = ""))
val response = client.delete("/subscriptions/https:/www.youtube.com/channel/UC123?url=https%3A%2F%2Fwww.youtube.com%2Fchannel%2FUC123") {
headers.append(HttpHeaders.Authorization, "Bearer test-jwt")
}
assertEquals(HttpStatusCode.NoContent, response.status)
}
}