From a395726dbeda31179483e601de30f8512fa019d4 Mon Sep 17 00:00:00 2001 From: Alexander Botello Date: Sun, 28 Oct 2018 13:02:25 -0500 Subject: [PATCH] Call urllib.parse.unquote on decoded field value (#150) --- starlette/formparsers.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/starlette/formparsers.py b/starlette/formparsers.py index 4d6580ca..6d83320d 100644 --- a/starlette/formparsers.py +++ b/starlette/formparsers.py @@ -1,9 +1,11 @@ -from enum import Enum -from starlette.datastructures import Headers -import asyncio import io -import tempfile import typing +import asyncio +import tempfile +from enum import Enum +from urllib.parse import unquote + +from starlette.datastructures import Headers try: from multipart.multipart import parse_options_header @@ -69,27 +71,22 @@ class FormParser: self.messages = [] # type: typing.List[typing.Tuple[FormMessage, bytes]] def on_field_start(self) -> None: - print("on_field_start") message = (FormMessage.FIELD_START, b"") self.messages.append(message) def on_field_name(self, data: bytes, start: int, end: int) -> None: - print("on_field_name") message = (FormMessage.FIELD_NAME, data[start:end]) self.messages.append(message) def on_field_data(self, data: bytes, start: int, end: int) -> None: - print("on_field_data") message = (FormMessage.FIELD_DATA, data[start:end]) self.messages.append(message) def on_field_end(self) -> None: - print("on_field_end") message = (FormMessage.FIELD_END, b"") self.messages.append(message) def on_end(self) -> None: - print("on_end") message = (FormMessage.END, b"") self.messages.append(message) @@ -127,7 +124,9 @@ class FormParser: elif message_type == FormMessage.FIELD_DATA: field_value += message_bytes elif message_type == FormMessage.FIELD_END: - result[field_name.decode("latin-1")] = field_value.decode("latin-1") + result[field_name.decode("latin-1")] = unquote( + field_value.decode("latin-1") + ) elif message_type == FormMessage.END: pass