Commit 42cfff7d authored by Fredrik Lundh's avatar Fredrik Lundh

- change \x to mean "byte" also in unicode literals

  (patch #100912)
parent 8fb5f536
...@@ -1198,13 +1198,15 @@ PyObject *PyUnicode_DecodeUnicodeEscape(const char *s, ...@@ -1198,13 +1198,15 @@ PyObject *PyUnicode_DecodeUnicodeEscape(const char *s,
*p++ = x; *p++ = x;
break; 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': case 'x':
x = 0; x = 0;
c = (unsigned char)*s; c = (unsigned char)*s;
if (isxdigit(c)) { if (isxdigit(c)) {
do { do {
x = (x<<4) & ~0xF; x = (x<<4) & 0xF0;
if ('0' <= c && c <= '9') if ('0' <= c && c <= '9')
x += c - '0'; x += c - '0';
else if ('a' <= c && c <= 'f') else if ('a' <= c && c <= 'f')
...@@ -1213,7 +1215,7 @@ PyObject *PyUnicode_DecodeUnicodeEscape(const char *s, ...@@ -1213,7 +1215,7 @@ PyObject *PyUnicode_DecodeUnicodeEscape(const char *s,
x += 10 + c - 'A'; x += 10 + c - 'A';
c = (unsigned char)*++s; c = (unsigned char)*++s;
} while (isxdigit(c)); } while (isxdigit(c));
*p++ = x; *p++ = (unsigned char) x;
} else { } else {
*p++ = '\\'; *p++ = '\\';
*p++ = (unsigned char)s[-1]; *p++ = (unsigned char)s[-1];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment