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

Skip to content

Commit 61e40bd

Browse files
committed
Special case normalization of empty strings. Fixes #924361.
Backported to 2.3.
1 parent e5fced7 commit 61e40bd

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

Lib/test/test_unicodedata.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ def test_combining(self):
170170
def test_normalize(self):
171171
self.assertRaises(TypeError, self.db.normalize)
172172
self.assertRaises(ValueError, self.db.normalize, 'unknown', u'xx')
173+
self.assertEqual(self.db.normalize('NFKC', u''), u'')
173174
# The rest can be found in test_normalization.py
174175
# which requires an external file.
175176

Modules/unicodedata.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,13 @@ unicodedata_normalize(PyObject *self, PyObject *args)
515515
&form, &PyUnicode_Type, &input))
516516
return NULL;
517517

518+
if (PyUnicode_GetSize(input) == 0) {
519+
/* Special case empty input strings, since resizing
520+
them later would cause internal errors. */
521+
Py_INCREF(input);
522+
return input;
523+
}
524+
518525
if (strcmp(form, "NFC") == 0)
519526
return nfc_nfkc(input, 0);
520527
if (strcmp(form, "NFKC") == 0)

0 commit comments

Comments
 (0)