fix: apply _cookie_value_to_unicode to list-branch cookie key/value

This commit is contained in:
greymoth 2026-06-26 22:14:33 +09:00
parent 1d965dbc71
commit c59d32277d
2 changed files with 14 additions and 1 deletions

View File

@ -213,7 +213,7 @@ def request_to_curl(request: Request) -> str:
cookie = "; ".join(
f"{_cookie_value_to_unicode(c['name'])}={_cookie_value_to_unicode(c['value'])}"
if "name" in c and "value" in c
else f"{next(iter(c.keys()))}={next(iter(c.values()))}"
else f"{_cookie_value_to_unicode(next(iter(c.keys())))}={_cookie_value_to_unicode(next(iter(c.values())))}"
for c in request.cookies
)
cookies = f"--cookie '{cookie}'"

View File

@ -468,3 +468,16 @@ class TestRequestToCurl:
" --data-raw '{\"foo\": \"bar\"}' --cookie 'foo=1'"
)
self._test_request(request_object, expected_curl_command)
def test_cookies_list_bytes_nonstandard_key(self):
request_object = Request(
"https://www.httpbin.org/post",
method="POST",
cookies=[{b"foo": b"bar"}],
body=json.dumps({"foo": "bar"}),
)
expected_curl_command = (
"curl -X POST https://www.httpbin.org/post"
" --data-raw '{\"foo\": \"bar\"}' --cookie 'foo=bar'"
)
self._test_request(request_object, expected_curl_command)