Skip to content

Commit

Permalink
use UTF-8 as the default encoding for multipart text parts
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurdarcet committed Dec 16, 2016
1 parent ee4773a commit e61fab2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion aiohttp/multipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions tests/test_multipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, {},
Expand Down

0 comments on commit e61fab2

Please sign in to comment.