Skip to content

Commit

Permalink
Update url/resources/percent-encoding.py to work on Python 3 (#26643)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreu Botella authored Nov 25, 2020
1 parent 651219c commit 1783c9b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions url/resources/percent-encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""<!doctype html>
Expand Down

0 comments on commit 1783c9b

Please sign in to comment.