From e61fab2512d851a1c75eda53cc853f4600e1ef04 Mon Sep 17 00:00:00 2001 From: Arthur Darcet Date: Fri, 16 Dec 2016 11:30:19 +0100 Subject: [PATCH] use UTF-8 as the default encoding for multipart text parts --- aiohttp/multipart.py | 4 +++- tests/test_multipart.py | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/aiohttp/multipart.py b/aiohttp/multipart.py index 9c2c7db80ed..43b283446b4 100644 --- a/aiohttp/multipart.py +++ b/aiohttp/multipart.py @@ -394,7 +394,9 @@ def text(self, *, encoding=None): :rtype: str """ data = yield from self.read(decode=True) - encoding = encoding or self.get_charset(default='latin1') + # see https://www.w3.org/TR/html5/forms.html#multipart/form-data-encoding-algorithm + # and https://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#dom-xmlhttprequest-send + encoding = encoding or self.get_charset(default='utf-8') return data.decode(encoding) @asyncio.coroutine diff --git a/tests/test_multipart.py b/tests/test_multipart.py index 37397c2e887..e82e28e0251 100644 --- a/tests/test_multipart.py +++ b/tests/test_multipart.py @@ -361,6 +361,13 @@ def test_read_text(self): result = yield from obj.text() self.assertEqual('Hello, world!', result) + def test_read_text_default_encoding(self): + obj = aiohttp.multipart.BodyPartReader( + self.boundary, {}, + Stream('Привет, Мир!\r\n--:--'.encode('utf-8'))) + result = yield from obj.text() + self.assertEqual('Привет, Мир!', result) + def test_read_text_encoding(self): obj = aiohttp.multipart.BodyPartReader( self.boundary, {},