[issue21331] Reversing an encoding with unicode-escape returns a different result

Sworddragon report at bugs.python.org
Tue Apr 22 22:58:23 CEST 2014


New submission from Sworddragon:

I have made some tests with encoding/decoding in conjunction with unicode-escape and got some strange results:

>>> print('ä')
ä
>>> print('ä'.encode('utf-8'))
b'\xc3\xa4'
>>> print('ä'.encode('utf-8').decode('unicode-escape'))
ä
>>> print('ä'.encode('utf-8').decode('unicode-escape').encode('unicode-escape'))
b'\\xc3\\xa4'
>>> print('ä'.encode('utf-8').decode('unicode-escape').encode('unicode-escape').decode('utf-8'))
\xc3\xa4


Shouldn't .decode('unicode-escape').encode('unicode-escape') nullify itself and so "'ä'.encode('utf-8').decode('unicode-escape').encode('unicode-escape')" return the same result as 'ä'.encode('utf-8')?

----------
components: Unicode
messages: 217021
nosy: Sworddragon, ezio.melotti, haypo
priority: normal
severity: normal
status: open
title: Reversing an encoding with unicode-escape returns a different result
type: behavior
versions: Python 3.4

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21331>
_______________________________________


More information about the Python-bugs-list mailing list