]> granicus.if.org Git - python/commitdiff
Special case normalization of empty strings. Fixes #924361.
authorMartin v. Löwis <martin@v.loewis.de>
Sat, 17 Apr 2004 19:36:48 +0000 (19:36 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Sat, 17 Apr 2004 19:36:48 +0000 (19:36 +0000)
Backported to 2.3.

Lib/test/test_unicodedata.py
Modules/unicodedata.c

index 61b4ffb133b39842fa710e60ca3e8501efd63444..8157fb38e49a52a835561398393614221d6aa508 100644 (file)
@@ -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.
 
index 311db296bdbcecacdef9c44e98be8ae79ef45fe1..ba218a3e58e89fd34be5246da348de62b12fe267 100644 (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)