Issue #26754: PyUnicode_FSDecoder() accepted a filename argument encoded as

an iterable of integers. Now only strings and byte-like objects are accepted.
This commit is contained in:
Serhiy Storchaka 2016-06-18 13:53:36 +03:00
parent bae5d81f5d
commit 9305d83425
6 changed files with 62 additions and 1 deletions

View file

@ -600,6 +600,19 @@ class UncompressedZipImportTestCase(ImportHooksBaseTestCase):
finally:
os.remove(filename)
def testBytesPath(self):
filename = support.TESTFN + ".zip"
self.addCleanup(support.unlink, filename)
with ZipFile(filename, "w") as z:
zinfo = ZipInfo(TESTMOD + ".py", time.localtime(NOW))
zinfo.compress_type = self.compression
z.writestr(zinfo, test_src)
zipimport.zipimporter(filename)
zipimport.zipimporter(os.fsencode(filename))
zipimport.zipimporter(bytearray(os.fsencode(filename)))
zipimport.zipimporter(memoryview(os.fsencode(filename)))
@support.requires_zlib
class CompressedZipImportTestCase(UncompressedZipImportTestCase):
@ -620,6 +633,8 @@ class BadFileZipImportTestCase(unittest.TestCase):
def testBadArgs(self):
self.assertRaises(TypeError, zipimport.zipimporter, None)
self.assertRaises(TypeError, zipimport.zipimporter, TESTMOD, kwd=None)
self.assertRaises(TypeError, zipimport.zipimporter,
list(os.fsencode(TESTMOD)))
def testFilenameTooLong(self):
self.assertZipFailure('A' * 33000)