From 3ecd8e6a571235691e85a9715c304b6732b655fc Mon Sep 17 00:00:00 2001 From: Andreu Botella Date: Wed, 25 Nov 2020 14:34:32 +0100 Subject: [PATCH] Update url/resources/percent-encoding.py to work on Python 3 --- url/resources/percent-encoding.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/url/resources/percent-encoding.py b/url/resources/percent-encoding.py index f7228871205a20..e8fbb7d3b3d265 100644 --- a/url/resources/percent-encoding.py +++ b/url/resources/percent-encoding.py @@ -7,15 +7,15 @@ def numeric_references(input): output = b"" for cp in input: - output += b"&#x" + format(ord(cp), b"X") + b";" + output += b"&#x" + format(ord(cp), u"X").encode(u"utf-8") + b";" return output def main(request, response): # Undo the "magic" space with + replacement as otherwise base64 decoding will fail. - value = request.GET.first(b"value").replace(" ", "+") + value = request.GET.first(b"value").replace(b" ", b"+") encoding = request.GET.first(b"encoding") - output_value = numeric_references(base64.b64decode(value).decode(b"utf-8")) + output_value = numeric_references(base64.b64decode(value).decode(u"utf-8")) return ( [(b"Content-Type", b"text/html;charset=" + encoding)], b"""