aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2024-01-06 17:02:32 +0100
committerTrygve Aaberge <trygveaa@gmail.com>2024-02-18 11:32:54 +0100
commit6b5f46d2e1550d94a9beee4b74dc5ba2b2ad5c2e (patch)
treec95aa2cef546d8acc04ae8dc580e06d38d7f8f8b
parentaf2c56f96d8be2f783332f5e4c502e8d15835b32 (diff)
downloadwee-slack-6b5f46d2e1550d94a9beee4b74dc5ba2b2ad5c2e.tar.gz
Use the api_cookie value as the `d` cookie if no keys are specified
Usually, only the `d` cookie is needed, so this allows you to only specify the value of that cookie without the key if you don't need to set any other cookies.
-rw-r--r--slack/util.py2
-rw-r--r--tests/test_get_cookies.py10
2 files changed, 12 insertions, 0 deletions
diff --git a/slack/util.py b/slack/util.py
index 14d18dc..cfe0e03 100644
--- a/slack/util.py
+++ b/slack/util.py
@@ -56,6 +56,8 @@ def url_encode_if_not_encoded(value: str) -> str:
def get_cookies(cookie_config: str) -> str:
cookie_pairs = [cookie.split("=", 1) for cookie in cookie_config.split(";")]
+ if len(cookie_pairs) == 1 and len(cookie_pairs[0]) == 1:
+ cookie_pairs[0].insert(0, "d")
for cookie_pair in cookie_pairs:
cookie_pair[0] = cookie_pair[0].strip()
cookie_pair[1] = url_encode_if_not_encoded(cookie_pair[1].strip())
diff --git a/tests/test_get_cookies.py b/tests/test_get_cookies.py
index 1e68f58..7222adf 100644
--- a/tests/test_get_cookies.py
+++ b/tests/test_get_cookies.py
@@ -1,6 +1,16 @@
from slack.util import get_cookies
+def test_get_cookies_without_key_value_encoded():
+ cookie = get_cookies("a%2Bb")
+ assert cookie == "d=a%2Bb"
+
+
+def test_get_cookies_without_key_value_not_encoded():
+ cookie = get_cookies("a+b")
+ assert cookie == "d=a%2Bb"
+
+
def test_get_cookies_multiple_keys_value_encoded():
cookie = get_cookies("d=a%2Bb ; d-s=1")
assert cookie == "d=a%2Bb; d-s=1"