diff options
author | Fredrik Lundh <fredrik@pythonware.com> | 2000-07-16 18:47:43 (GMT) |
---|---|---|
committer | Fredrik Lundh <fredrik@pythonware.com> | 2000-07-16 18:47:43 (GMT) |
commit | 0e19e76aba9f470c348e25bb2d550f9a096642bd (patch) | |
tree | 6e2584c8b196e13aeb312bc628513214a9acd878 /Objects | |
parent | 855ffac224c5bc65a23988ec352091033f35d9f4 (diff) | |
download | cpython-0e19e76aba9f470c348e25bb2d550f9a096642bd.zip cpython-0e19e76aba9f470c348e25bb2d550f9a096642bd.tar.gz cpython-0e19e76aba9f470c348e25bb2d550f9a096642bd.tar.bz2 |
- change \x to mean "byte" also in unicode literals
(patch #100912)
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/unicodeobject.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 989ad1f..3542879 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -1198,13 +1198,15 @@ PyObject *PyUnicode_DecodeUnicodeEscape(const char *s, *p++ = x; break; - /* \xXXXX escape with 0-4 hex digits */ + /* \xXXXX escape with 1-n hex digits. for compatibility + with 8-bit strings, this code ignores all but the last + two digits */ case 'x': x = 0; c = (unsigned char)*s; if (isxdigit(c)) { do { - x = (x<<4) & ~0xF; + x = (x<<4) & 0xF0; if ('0' <= c && c <= '9') x += c - '0'; else if ('a' <= c && c <= 'f') @@ -1213,7 +1215,7 @@ PyObject *PyUnicode_DecodeUnicodeEscape(const char *s, x += 10 + c - 'A'; c = (unsigned char)*++s; } while (isxdigit(c)); - *p++ = x; + *p++ = (unsigned char) x; } else { *p++ = '\\'; *p++ = (unsigned char)s[-1]; |