Skip to content

Commit a9f10b7

Browse files
committed
Map escape sequence name to uppercase before calling into unicodedata
1 parent 33838fe commit a9f10b7

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Literals using the ``\N{name}`` escape syntax can now construct CJK
2+
ideographs and Hangul syllables using case-insensitive names.

Objects/unicodeobject.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6011,9 +6011,18 @@ _PyUnicode_DecodeUnicodeEscapeInternal(const char *s,
60116011
if (namelen) {
60126012
/* found a name. look it up in the unicode database */
60136013
s++;
6014+
6015+
/* map to uppercase before calling getcode, which does
6016+
* case-sensitive comparisons */
6017+
char buffer[namelen];
6018+
size_t i;
6019+
for (i = 0; i < namelen; i++) {
6020+
buffer[i] = Py_TOUPPER(start[i]);
6021+
}
6022+
60146023
ch = 0xffffffff; /* in case 'getcode' messes up */
60156024
if (namelen <= INT_MAX &&
6016-
ucnhash_capi->getcode(start, (int)namelen,
6025+
ucnhash_capi->getcode(buffer, (int)namelen,
60176026
&ch, 0)) {
60186027
assert(ch <= MAX_UNICODE);
60196028
WRITE_CHAR(ch);

0 commit comments

Comments
 (0)