[issue7615] unicode_escape codec does not escape quotes

Richard Hansen report at bugs.python.org
Mon Jan 4 00:13:07 CET 2010


Richard Hansen <rhansen at bbn.com> added the comment:

> If we change this, the encoder should quote both single and double 
> quotes - simply because it is not known whether the literal 
> will use single or double quotes.

Or document that single quotes are always escaped so that the user knows he/she can safely use u''.  I'm not sure if there is a use case where both would *need* to be escaped, and escaping both has a size penalty.

I've attached an untested patch that escapes both.

If both are escaped, then the behavior of the string_escape codec should also be changed for consistency (it only escapes single quotes).

> The raw_unicode_escape codec would have to be fixed as well.

I'm not sure there's anything to fix.  Adding backslashes to quotes in raw strings changes the value of the string -- the backslashes prevent the quotes from ending the string literal, but they are not removed when the raw literal is evaluated.

Perhaps raw_unicode_escape should be "fixed" by raising an exception when it contains any quotes.

----------
Added file: http://bugs.python.org/file15729/unicode_escape_single_and_double_quotes.patch

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


More information about the Python-bugs-list mailing list