[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [bridgedb/main] Added additional codecs for decoding HTTP requests
commit dbbd7fae44539b9db397ef42dd8e60ba58a83bc2
Author: Armin Huremagic <columbeff@xxxxxxxxx>
Date: Thu Nov 18 23:57:42 2021 +0100
Added additional codecs for decoding HTTP requests
In case the request is not 'utf-8' encoded, this fix checks for additional codecs, in this case 'latin-1' and adds a try-catch block to it.
---
bridgedb/distributors/https/server.py | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/bridgedb/distributors/https/server.py b/bridgedb/distributors/https/server.py
index 818e2e0..81d8e81 100644
--- a/bridgedb/distributors/https/server.py
+++ b/bridgedb/distributors/https/server.py
@@ -107,9 +107,15 @@ def stringifyRequestArgs(args):
# Convert all key/value pairs from bytes to str.
str_args = {}
for arg, values in args.items():
- arg = arg if isinstance(arg, str) else arg.decode("utf-8")
- values = [value.decode("utf-8") if isinstance(value, bytes)
- else value for value in values]
+ codecs = ["utf-8", "latin-1"]
+ for c in codecs:
+ try:
+ arg = arg if isinstance(arg, str) else arg.decode(c)
+ values = [value.decode(c) if isinstance(value, bytes) else value for value in values]
+ except UnicodeDecodeError:
+ continue
+ else:
+ break
str_args[arg] = values
return str_args
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits