mirror of
https://github.com/python/cpython.git
synced 2025-08-22 09:45:06 +00:00
Backport checkin:
Change decode() so that it works with a buffer (i.e. unicode(..., 'utf-8-sig')) SF bug #1601501.
This commit is contained in:
parent
2396f4c3b1
commit
9ff1d39402
2 changed files with 5 additions and 1 deletions
|
@ -16,7 +16,7 @@ def encode(input, errors='strict'):
|
||||||
|
|
||||||
def decode(input, errors='strict'):
|
def decode(input, errors='strict'):
|
||||||
prefix = 0
|
prefix = 0
|
||||||
if input.startswith(codecs.BOM_UTF8):
|
if input[:3] == codecs.BOM_UTF8:
|
||||||
input = input[3:]
|
input = input[3:]
|
||||||
prefix = 3
|
prefix = 3
|
||||||
(output, consumed) = codecs.utf_8_decode(input, errors, True)
|
(output, consumed) = codecs.utf_8_decode(input, errors, True)
|
||||||
|
|
|
@ -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):
|
class EscapeDecodeTest(unittest.TestCase):
|
||||||
def test_empty(self):
|
def test_empty(self):
|
||||||
self.assertEquals(codecs.escape_decode(""), ("", 0))
|
self.assertEquals(codecs.escape_decode(""), ("", 0))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue