Handle latin-1 URL encoding. I didn't think that was still a thing.

This commit is contained in:
Klaus-Uwe Mitterer 2017-10-01 09:15:22 +02:00
parent d52dbd8384
commit 52c32dcc83

15
main.py
View file

@ -28,7 +28,7 @@ def application(env, re):
if len(split) > 2:
re("400 Bad Request", [])
yield "<h1>400 Bad Request</h1>".encode()
yield "Only one (validate) or two (conn) arguments may be passed as path."
yield "Only one (validate) or two (conn) arguments may be passed as path.".encode()
return
if len(split) > 0:
@ -52,8 +52,12 @@ def application(env, re):
if rtype.lower() in ["conn", "connection"]:
try:
frm = cfrm or args["from"][0]
to = cto or args["to"][0]
try:
frm = (cfrm or args["from"][0]).encode("latin-1").decode("utf-8")
to = (cto or args["to"][0]).encode("latin-1").decode("utf-8")
except UnicodeDecodeError:
frm = cfrm or args["from"][0]
to = cto or args["to"][0]
if not frm or not to:
raise ValueError()
@ -103,7 +107,10 @@ def application(env, re):
elif rtype.lower() in ["val", "validate"]:
try:
name = cfrm or args["name"]
try:
name = (cfrm or args["from"][0]).encode("latin-1").decode("utf-8")
except UnicodeDecodeError:
name = cfrm or args["from"][0]
if not name:
raise ValueError()