@@ -228,6 +228,7 @@ def test_add_dir_getmember(self):
228228defadd_dir_and_getmember(self, name):
229229withos_helper.temp_cwd():
230230withtarfile.open(tmpname, 'w') astar:
231+tar.format=tarfile.USTAR_FORMAT
231232try:
232233os.mkdir(name)
233234tar.add(name)
@@ -1006,11 +1007,26 @@ def test_header_offset(self):
10061007"iso8859-1", "strict")
10071008self.assertEqual(tarinfo.type, self.longnametype)
100810091010+deftest_longname_directory(self):
1011+# Test reading a longlink directory. Issue #47231.
1012+longdir= ('a'*101) +'/'
1013+withos_helper.temp_cwd():
1014+withtarfile.open(tmpname, 'w') astar:
1015+tar.format=self.format
1016+try:
1017+os.mkdir(longdir)
1018+tar.add(longdir)
1019+finally:
1020+os.rmdir(longdir)
1021+withtarfile.open(tmpname) astar:
1022+self.assertIsNotNone(tar.getmember(longdir))
1023+self.assertIsNotNone(tar.getmember(longdir.removesuffix('/')))
1009102410101025classGNUReadTest(LongnameTest, ReadTest, unittest.TestCase):
1011102610121027subdir="gnu"
10131028longnametype=tarfile.GNUTYPE_LONGNAME
1029+format=tarfile.GNU_FORMAT
1014103010151031# Since 3.2 tarfile is supposed to accurately restore sparse members and
10161032# produce files with holes. This is what we actually want to test here.
@@ -1070,6 +1086,7 @@ class PaxReadTest(LongnameTest, ReadTest, unittest.TestCase):
1070108610711087subdir="pax"
10721088longnametype=tarfile.XHDTYPE
1089+format=tarfile.PAX_FORMAT
1073109010741091deftest_pax_global_headers(self):
10751092tar=tarfile.open(tarname, encoding="iso8859-1")