From a3ca887a373b1781fb496d6ff42c40418d75e263 Mon Sep 17 00:00:00 2001 From: Unrud Date: Mon, 14 Sep 2020 21:20:39 +0200 Subject: [PATCH] Fix exceptions raised by decode_request --- radicale/httputils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/radicale/httputils.py b/radicale/httputils.py index 167a86b..6911e15 100644 --- a/radicale/httputils.py +++ b/radicale/httputils.py @@ -80,6 +80,10 @@ def decode_request(configuration, environ, text): # Then append various fallbacks charsets.append("utf-8") charsets.append("iso8859-1") + # Remove duplicates + for i, s in reversed(list(enumerate(charsets))): + if s in charsets[:i]: + del charsets[i] # Try to decode for charset in charsets: @@ -87,7 +91,8 @@ def decode_request(configuration, environ, text): return text.decode(charset) except UnicodeDecodeError: pass - raise UnicodeDecodeError + raise UnicodeDecodeError("decode_request", text, 0, len(text), + "all codecs failed [%s]" % ", ".join(charsets)) def read_raw_request_body(configuration, environ):