Support specifying both url encoded and raw (not url encoded) cookies
@@ -59,9 +59,9 @@ except ImportError:
Reversible = object
try:
- from urllib.parse import quote, urlencode
+ from urllib.parse import quote, unquote, urlencode
except ImportError:
- from urllib import quote, urlencode
+ from urllib import quote, unquote, urlencode
try:
JSONDecodeError = json.JSONDecodeError
@@ -393,6 +393,15 @@ def format_exc_only():
return "".join(decode_from_utf8(traceback.format_exception_only(etype, value)))
+def url_encode_if_not_encoded(value):
+ decoded = unquote(value)
+ is_encoded = value != decoded
+ if is_encoded:
+ return value
+ else:
+ return quote(value)
+
+
def get_localvar_type(slack_type):
if slack_type in ("im", "mpim"):
return "private"
@@ -1478,7 +1487,10 @@ class SlackRequest(object):
def options(self):
cookies = "; ".join(
- ["{}={}".format(key, value) for key, value in self.cookies.items()]
+ [
+ "{}={}".format(key, url_encode_if_not_encoded(value))
+ for key, value in self.cookies.items()
+ ]
)
return {
"useragent": "wee_slack {}".format(SCRIPT_VERSION),
