Fix escaping of non-ASCII characters.
authorMartin v. Löwis <martin@v.loewis.de>
Mon, 9 Sep 2002 06:17:05 +0000 (06:17 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Mon, 9 Sep 2002 06:17:05 +0000 (06:17 +0000)
Lib/test/test_pep263.py
Objects/stringobject.c

index b1ffc033c04dc4ffd2078cf5f30792908b4cbfa2..7cc55265f00e9bbf54d71c70e15c5428e66164bc 100644 (file)
@@ -1,2 +1,3 @@
 #! -*- coding: koi8-r -*-
 assert u"ðÉÔÏÎ".encode("utf-8") == '\xd0\x9f\xd0\xb8\xd1\x82\xd0\xbe\xd0\xbd'
+assert u"\ð".encode("utf-8") == '\\\xd0\x9f'
index dd38ee3c859605531ade7ff7136daf428c7bdc38..c090e9b2d6a12b521b5b1c9cb4241a7e74ef13b4 100644 (file)
@@ -541,6 +541,7 @@ PyObject *PyString_DecodeEscape(const char *s,
        end = s + len;
        while (s < end) {
                if (*s != '\\') {
+                 non_esc:
 #ifdef Py_USING_UNICODE
                        if (recode_encoding && (*s & 0x80)) {
                                PyObject *u, *w;
@@ -656,8 +657,9 @@ PyObject *PyString_DecodeEscape(const char *s,
 #endif
                default:
                        *p++ = '\\';
-                       *p++ = s[-1];
-                       break;
+                       s--;
+                       goto non_esc; /* an arbitry number of unescaped
+                                        UTF-8 bytes may follow. */
                }
        }
        if (p-buf < newlen)