]> granicus.if.org Git - python/commitdiff
Backport checkin:
authorWalter Dörwald <walter@livinglogic.de>
Thu, 23 Nov 2006 05:06:31 +0000 (05:06 +0000)
committerWalter Dörwald <walter@livinglogic.de>
Thu, 23 Nov 2006 05:06:31 +0000 (05:06 +0000)
Change decode() so that it works with a buffer (i.e. unicode(..., 'utf-8-sig'))
SF bug #1601501.

Lib/encodings/utf_8_sig.py
Lib/test/test_codecs.py

index f05f6b88db26eda0c18eaade3b0b78d97a75ac7e..d751da69c41585778d5a92783381d0c737b094c4 100644 (file)
@@ -16,7 +16,7 @@ def encode(input, errors='strict'):
 
 def decode(input, errors='strict'):
     prefix = 0
-    if input.startswith(codecs.BOM_UTF8):
+    if input[:3] == codecs.BOM_UTF8:
         input = input[3:]
         prefix = 3
     (output, consumed) = codecs.utf_8_decode(input, errors, True)
index 62cd1637af6e564f4a7fb497e03530951389460f..185670bb19e817a5cd7ad5c858c95f10eb8ab90e 100644 (file)
@@ -426,6 +426,10 @@ class UTF8SigTest(ReadTest):
             ]
         )
 
+    def test_bug1601501(self):
+        # SF bug #1601501: check that the codec works with a buffer
+        unicode("\xef\xbb\xbf", "utf-8-sig")
+
 class EscapeDecodeTest(unittest.TestCase):
     def test_empty(self):
         self.assertEquals(codecs.escape_decode(""), ("", 0))