[issue7615] unicode_escape codec does not escape quotes
Richard Hansen
report at bugs.python.org
Fri Jan 1 04:28:27 CET 2010
New submission from Richard Hansen <rhansen at bbn.com>:
The description of the unicode_escape codec says that it produces "a
string that is suitable as Unicode literal in Python source code." [1]
Unfortunately, this is not true as it does not escape quotes. For example:
print u'a\'b"c\'\'\'d"""e'.encode('unicode_escape')
outputs:
a'b"c'''d"""e
I have attached a patch that fixes this issue by escaping single quotes.
With the patch applied, the output is:
a\'b"c\'\'\'d"""e
I chose to only escape single quotes because:
1. it simplifies the patch, and
2. it matches string_escape's behavior.
[1] http://docs.python.org/library/codecs.html#standard-encodings
----------
components: Unicode
files: unicode_escape_single_quotes.patch
keywords: patch
messages: 97112
nosy: rhansen
severity: normal
status: open
title: unicode_escape codec does not escape quotes
type: behavior
versions: Python 2.6, Python 2.7
Added file: http://bugs.python.org/file15716/unicode_escape_single_quotes.patch
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue7615>
_______________________________________
More information about the Python-bugs-list
mailing list