mirror of https://github.com/python/cpython
Special case normalization of empty strings. Fixes #924361.
Backported to 2.3.
This commit is contained in:
parent
e5fced781b
commit
61e40bd897
|
@ -170,6 +170,7 @@ class UnicodeFunctionsTest(UnicodeDatabaseTest):
|
|||
def test_normalize(self):
|
||||
self.assertRaises(TypeError, self.db.normalize)
|
||||
self.assertRaises(ValueError, self.db.normalize, 'unknown', u'xx')
|
||||
self.assertEqual(self.db.normalize('NFKC', u''), u'')
|
||||
# The rest can be found in test_normalization.py
|
||||
# which requires an external file.
|
||||
|
||||
|
|
|
@ -515,6 +515,13 @@ unicodedata_normalize(PyObject *self, PyObject *args)
|
|||
&form, &PyUnicode_Type, &input))
|
||||
return NULL;
|
||||
|
||||
if (PyUnicode_GetSize(input) == 0) {
|
||||
/* Special case empty input strings, since resizing
|
||||
them later would cause internal errors. */
|
||||
Py_INCREF(input);
|
||||
return input;
|
||||
}
|
||||
|
||||
if (strcmp(form, "NFC") == 0)
|
||||
return nfc_nfkc(input, 0);
|
||||
if (strcmp(form, "NFKC") == 0)
|
||||
|
|
Loading…
Reference in New Issue