Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0e19e76

Browse files
author
Fredrik Lundh
committed
- change \x to mean "byte" also in unicode literals
(patch #100912)
1 parent 855ffac commit 0e19e76

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

Objects/unicodeobject.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,13 +1198,15 @@ PyObject *PyUnicode_DecodeUnicodeEscape(const char *s,
11981198
*p++ = x;
11991199
break;
12001200

1201-
/* \xXXXX escape with 0-4 hex digits */
1201+
/* \xXXXX escape with 1-n hex digits. for compatibility
1202+
with 8-bit strings, this code ignores all but the last
1203+
two digits */
12021204
case 'x':
12031205
x = 0;
12041206
c = (unsigned char)*s;
12051207
if (isxdigit(c)) {
12061208
do {
1207-
x = (x<<4) & ~0xF;
1209+
x = (x<<4) & 0xF0;
12081210
if ('0' <= c && c <= '9')
12091211
x += c - '0';
12101212
else if ('a' <= c && c <= 'f')
@@ -1213,7 +1215,7 @@ PyObject *PyUnicode_DecodeUnicodeEscape(const char *s,
12131215
x += 10 + c - 'A';
12141216
c = (unsigned char)*++s;
12151217
} while (isxdigit(c));
1216-
*p++ = x;
1218+
*p++ = (unsigned char) x;
12171219
} else {
12181220
*p++ = '\\';
12191221
*p++ = (unsigned char)s[-1];

0 commit comments

Comments
 (0)