Не подтверждена Коммит 69792c36 создал по автору Rustam's avatar Rustam Зафиксировано автором GitHub
Просмотр файлов

KTOR-4722 renderSetCookieHeader should not encode extensions (#3172)

владелец d6b9a87c
...@@ -157,8 +157,8 @@ public fun renderSetCookieHeader( ...@@ -157,8 +157,8 @@ public fun renderSetCookieHeader(
cookiePartFlag("Secure", secure), cookiePartFlag("Secure", secure),
cookiePartFlag("HttpOnly", httpOnly) cookiePartFlag("HttpOnly", httpOnly)
) + extensions.map { cookiePartExt(it.key.assertCookieName(), it.value, encoding) } + ) + extensions.map { cookiePartExt(it.key.assertCookieName(), it.value) } +
if (includeEncoding) cookiePartExt("\$x-enc", encoding.name, CookieEncoding.RAW) else "" if (includeEncoding) cookiePartExt("\$x-enc", encoding.name) else ""
).filter { it.isNotEmpty() } ).filter { it.isNotEmpty() }
.joinToString("; ") .joinToString("; ")
...@@ -221,7 +221,7 @@ private inline fun cookiePartFlag(name: String, value: Boolean) = ...@@ -221,7 +221,7 @@ private inline fun cookiePartFlag(name: String, value: Boolean) =
if (value) name else "" if (value) name else ""
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
private inline fun cookiePartExt(name: String, value: String?, encoding: CookieEncoding) = private inline fun cookiePartExt(name: String, value: String?) =
if (value == null) cookiePartFlag(name, true) else cookiePart(name, value, encoding) if (value == null) cookiePartFlag(name, true) else cookiePart(name, value, CookieEncoding.RAW)
private fun String.toIntClamping(): Int = toLong().coerceIn(0L, Int.MAX_VALUE.toLong()).toInt() private fun String.toIntClamping(): Int = toLong().coerceIn(0L, Int.MAX_VALUE.toLong()).toInt()
/*
* Copyright 2014-2022 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/
package io.ktor.tests.http
import io.ktor.http.*
import kotlin.test.*
class RenderSetCookieTest {
@Test
fun renderCookieDoesntEncodeExtensions() {
val cookie = Cookie(
"name",
"value",
encoding = CookieEncoding.BASE64_ENCODING,
extensions = mapOf("foo" to "bar")
)
val rendered = renderSetCookieHeader(cookie)
assertEquals("name=dmFsdWU=; foo=bar; \$x-enc=BASE64_ENCODING", rendered)
}
@Test
fun renderCookieThrowsOnNotEncodedExtensions() {
val cookie = Cookie(
"name",
"value",
encoding = CookieEncoding.BASE64_ENCODING,
extensions = mapOf("foo" to "b,ar")
)
assertFailsWith<IllegalArgumentException> {
renderSetCookieHeader(cookie)
}
}
}
Поддерживает Markdown
0% или .
You are about to add 0 people to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать