From: Walter Dörwald Date: Thu, 23 Nov 2006 05:06:31 +0000 (+0000) Subject: Backport checkin: X-Git-Tag: v2.5.1c1~238 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9ff1d394027c1ae08d15df149bb1ee5a62f566de;p=thirdparty%2FPython%2Fcpython.git Backport checkin: Change decode() so that it works with a buffer (i.e. unicode(..., 'utf-8-sig')) SF bug #1601501. --- diff --git a/Lib/encodings/utf_8_sig.py b/Lib/encodings/utf_8_sig.py index f05f6b88db26..d751da69c415 100644 --- a/Lib/encodings/utf_8_sig.py +++ b/Lib/encodings/utf_8_sig.py @@ -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) diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py index 62cd1637af6e..185670bb19e8 100644 --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -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))