]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
- change \x to mean "byte" also in unicode literals
authorFredrik Lundh <fredrik@pythonware.com>
Sun, 16 Jul 2000 18:47:43 +0000 (18:47 +0000)
committerFredrik Lundh <fredrik@pythonware.com>
Sun, 16 Jul 2000 18:47:43 +0000 (18:47 +0000)
  (patch #100912)

Objects/unicodeobject.c

index 989ad1fdbb794d74a305e8ac10b77bde5d60e4ba..3542879bc5fbd12f04475f04d1cd54479953da0a 100644 (file)
@@ -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];