Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 05459c5

Browse files
committed
Accept u"..." literals even when Unicode is disabled. But these
literals must not contain \u, \U or \N escapes. (XXX Should they also not contain non-ASCII characters?)
1 parent c88da1f commit 05459c5

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

Python/compile.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,19 +1130,12 @@ parsestr(struct compiling *com, char *s)
11301130
int first = *s;
11311131
int quote = first;
11321132
int rawmode = 0;
1133-
#ifdef Py_USING_UNICODE
11341133
int unicode = 0;
1135-
#endif
1134+
11361135
if (isalpha(quote) || quote == '_') {
11371136
if (quote == 'u' || quote == 'U') {
1138-
#ifdef Py_USING_UNICODE
11391137
quote = *++s;
11401138
unicode = 1;
1141-
#else
1142-
com_error(com, PyExc_SyntaxError,
1143-
"Unicode literals not supported in this Python");
1144-
return NULL;
1145-
#endif
11461139
}
11471140
if (quote == 'r' || quote == 'R') {
11481141
quote = *++s;
@@ -1250,6 +1243,18 @@ parsestr(struct compiling *com, char *s)
12501243
com_error(com, PyExc_ValueError,
12511244
"invalid \\x escape");
12521245
return NULL;
1246+
#ifndef Py_USING_UNICODE
1247+
case 'u':
1248+
case 'U':
1249+
case 'N':
1250+
if (unicode) {
1251+
Py_DECREF(v);
1252+
com_error(com, PyExc_ValueError,
1253+
"Unicode escapes not legal "
1254+
"when Unicode disabled");
1255+
return NULL;
1256+
}
1257+
#endif
12531258
default:
12541259
*p++ = '\\';
12551260
*p++ = s[-1];

0 commit comments

Comments
 (0)