File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ];
You can’t perform that action at this time.
0 commit comments