Открыть боковую панель
Aurora OS
Kotlin Multiplatform
Libraries
ktor
Коммиты
69792c36
Не подтверждена
Коммит
69792c36
создал
Окт 04, 2022
по автору
Rustam
Зафиксировано автором
GitHub
Окт 04, 2022
Просмотр файлов
KTOR-4722 renderSetCookieHeader should not encode extensions (#3172)
владелец
d6b9a87c
Изменения
2
Скрыть пробелы
Построчно
Рядом
ktor-http/common/src/io/ktor/http/Cookie.kt
Просмотр файла @
69792c36
...
@@ -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
,
e
ncoding
)
if
(
value
==
null
)
cookiePartFlag
(
name
,
true
)
else
cookiePart
(
name
,
value
,
CookieE
ncoding
.
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
()
ktor-http/common/test/io/ktor/tests/http/RenderSetCookieTest.kt
0 → 100644
Просмотр файла @
69792c36
/*
* 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.
Сначала завершите редактирование этого сообщения!
Отмена
Пожалуйста,
зарегистрируйтесь
или
войдите
чтобы прокомментировать