mirror of
https://github.com/python/cpython.git
synced 2025-11-02 11:08:57 +00:00
Fix escaping of non-ASCII characters.
This commit is contained in:
parent
8a64d40949
commit
2412853f8e
2 changed files with 5 additions and 2 deletions
|
|
@ -1,2 +1,3 @@
|
||||||
#! -*- coding: koi8-r -*-
|
#! -*- 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\xd0\xb8\xd1\x82\xd0\xbe\xd0\xbd'
|
||||||
|
assert u"\ð".encode("utf-8") == '\\\xd0\x9f'
|
||||||
|
|
|
||||||
|
|
@ -541,6 +541,7 @@ PyObject *PyString_DecodeEscape(const char *s,
|
||||||
end = s + len;
|
end = s + len;
|
||||||
while (s < end) {
|
while (s < end) {
|
||||||
if (*s != '\\') {
|
if (*s != '\\') {
|
||||||
|
non_esc:
|
||||||
#ifdef Py_USING_UNICODE
|
#ifdef Py_USING_UNICODE
|
||||||
if (recode_encoding && (*s & 0x80)) {
|
if (recode_encoding && (*s & 0x80)) {
|
||||||
PyObject *u, *w;
|
PyObject *u, *w;
|
||||||
|
|
@ -656,8 +657,9 @@ PyObject *PyString_DecodeEscape(const char *s,
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
*p++ = '\\';
|
*p++ = '\\';
|
||||||
*p++ = s[-1];
|
s--;
|
||||||
break;
|
goto non_esc; /* an arbitry number of unescaped
|
||||||
|
UTF-8 bytes may follow. */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (p-buf < newlen)
|
if (p-buf < newlen)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue