Skip to content

Commit 38ff9d6

Browse files
committed
[python] Quote special cookie characters other than special base64 characters
1 parent 07e3e01 commit 38ff9d6

8 files changed

Lines changed: 16 additions & 16 deletions

File tree

modules/openapi-generator/src/main/resources/python/api_client.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,8 +684,8 @@ class ApiClient:
684684
headers['Cookie'] = ""
685685
else:
686686
headers['Cookie'] += "; "
687-
# Encode spaces and semicolons in cookie value, leaving other characters as-is
688-
cookie_value = str(auth_setting['value']).replace(" ", "%20").replace(";", "%3B")
687+
# Account for cookie value containing spaces and special characters, excluding base64 delimiters
688+
cookie_value = quote(str(auth_setting['value']), safe='+/=')
689689
headers['Cookie'] += f"{auth_setting['key']}={cookie_value}"
690690
elif auth_setting['in'] == 'header':
691691
if auth_setting['type'] != 'http-signature':

samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,8 +677,8 @@ def _apply_auth_params(
677677
headers['Cookie'] = ""
678678
else:
679679
headers['Cookie'] += "; "
680-
# Encode spaces and semicolons in cookie value, leaving other characters as-is
681-
cookie_value = str(auth_setting['value']).replace(" ", "%20").replace(";", "%3B")
680+
# Account for cookie value containing spaces and special characters, excluding base64 delimiters
681+
cookie_value = quote(str(auth_setting['value']), safe='+/=')
682682
headers['Cookie'] += f"{auth_setting['key']}={cookie_value}"
683683
elif auth_setting['in'] == 'header':
684684
if auth_setting['type'] != 'http-signature':

samples/client/echo_api/python/openapi_client/api_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,8 +677,8 @@ def _apply_auth_params(
677677
headers['Cookie'] = ""
678678
else:
679679
headers['Cookie'] += "; "
680-
# Encode spaces and semicolons in cookie value, leaving other characters as-is
681-
cookie_value = str(auth_setting['value']).replace(" ", "%20").replace(";", "%3B")
680+
# Account for cookie value containing spaces and special characters, excluding base64 delimiters
681+
cookie_value = quote(str(auth_setting['value']), safe='+/=')
682682
headers['Cookie'] += f"{auth_setting['key']}={cookie_value}"
683683
elif auth_setting['in'] == 'header':
684684
if auth_setting['type'] != 'http-signature':

samples/openapi3/client/petstore/python-aiohttp/petstore_api/api_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -679,8 +679,8 @@ def _apply_auth_params(
679679
headers['Cookie'] = ""
680680
else:
681681
headers['Cookie'] += "; "
682-
# Encode spaces and semicolons in cookie value, leaving other characters as-is
683-
cookie_value = str(auth_setting['value']).replace(" ", "%20").replace(";", "%3B")
682+
# Account for cookie value containing spaces and special characters, excluding base64 delimiters
683+
cookie_value = quote(str(auth_setting['value']), safe='+/=')
684684
headers['Cookie'] += f"{auth_setting['key']}={cookie_value}"
685685
elif auth_setting['in'] == 'header':
686686
if auth_setting['type'] != 'http-signature':

samples/openapi3/client/petstore/python-httpx-sync/petstore_api/api_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -679,8 +679,8 @@ def _apply_auth_params(
679679
headers['Cookie'] = ""
680680
else:
681681
headers['Cookie'] += "; "
682-
# Encode spaces and semicolons in cookie value, leaving other characters as-is
683-
cookie_value = str(auth_setting['value']).replace(" ", "%20").replace(";", "%3B")
682+
# Account for cookie value containing spaces and special characters, excluding base64 delimiters
683+
cookie_value = quote(str(auth_setting['value']), safe='+/=')
684684
headers['Cookie'] += f"{auth_setting['key']}={cookie_value}"
685685
elif auth_setting['in'] == 'header':
686686
if auth_setting['type'] != 'http-signature':

samples/openapi3/client/petstore/python-httpx/petstore_api/api_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -679,8 +679,8 @@ def _apply_auth_params(
679679
headers['Cookie'] = ""
680680
else:
681681
headers['Cookie'] += "; "
682-
# Encode spaces and semicolons in cookie value, leaving other characters as-is
683-
cookie_value = str(auth_setting['value']).replace(" ", "%20").replace(";", "%3B")
682+
# Account for cookie value containing spaces and special characters, excluding base64 delimiters
683+
cookie_value = quote(str(auth_setting['value']), safe='+/=')
684684
headers['Cookie'] += f"{auth_setting['key']}={cookie_value}"
685685
elif auth_setting['in'] == 'header':
686686
if auth_setting['type'] != 'http-signature':

samples/openapi3/client/petstore/python-lazyImports/petstore_api/api_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,8 +676,8 @@ def _apply_auth_params(
676676
headers['Cookie'] = ""
677677
else:
678678
headers['Cookie'] += "; "
679-
# Encode spaces and semicolons in cookie value, leaving other characters as-is
680-
cookie_value = str(auth_setting['value']).replace(" ", "%20").replace(";", "%3B")
679+
# Account for cookie value containing spaces and special characters, excluding base64 delimiters
680+
cookie_value = quote(str(auth_setting['value']), safe='+/=')
681681
headers['Cookie'] += f"{auth_setting['key']}={cookie_value}"
682682
elif auth_setting['in'] == 'header':
683683
if auth_setting['type'] != 'http-signature':

samples/openapi3/client/petstore/python/petstore_api/api_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,8 +676,8 @@ def _apply_auth_params(
676676
headers['Cookie'] = ""
677677
else:
678678
headers['Cookie'] += "; "
679-
# Encode spaces and semicolons in cookie value, leaving other characters as-is
680-
cookie_value = str(auth_setting['value']).replace(" ", "%20").replace(";", "%3B")
679+
# Account for cookie value containing spaces and special characters, excluding base64 delimiters
680+
cookie_value = quote(str(auth_setting['value']), safe='+/=')
681681
headers['Cookie'] += f"{auth_setting['key']}={cookie_value}"
682682
elif auth_setting['in'] == 'header':
683683
if auth_setting['type'] != 'http-signature':

0 commit comments

Comments
 (0)