Skip to content

Commit 14689d5

Browse files
committed
gh-127636: Clarify the trailing-slash tarfile test
Note that './mydir/' is a regular-file member, not DIRTYPE, so a future reader does not turn it into a directory and lose the regression coverage. Also assert the member actually extracts as a file rather than only checking that extract() does not raise.
1 parent accf30a commit 14689d5

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

Lib/test/test_tarfile.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,17 @@ def test_add_dir_getmember(self):
255255
self.add_dir_and_getmember('a'*101)
256256

257257
def test_extract_name_with_trailing_slash(self):
258+
# gh-127636: './mydir/' is deliberately a regular-file member
259+
# (REGTYPE, not DIRTYPE) whose stored name ends in a slash. It
260+
# extracts as a file. Do not "fix" this by setting DIRTYPE; the
261+
# trailing-slash name on a non-directory is what is being tested.
258262
with tarfile.open(tmpname, 'w') as tar:
259263
tar.addfile(tarfile.TarInfo('./mydir/'))
260-
with tarfile.open(tmpname) as tar:
264+
with os_helper.temp_dir() as tmpdir, tarfile.open(tmpname) as tar:
261265
names = tar.getnames()
262266
self.assertEqual(names, ['./mydir/'])
263-
tar.extract(names[0], TEMPDIR, filter='fully_trusted')
267+
tar.extract(names[0], tmpdir, filter='fully_trusted')
268+
self.assertTrue(os.path.isfile(os.path.join(tmpdir, 'mydir')))
264269

265270
@unittest.skipUnless(hasattr(os, "getuid") and hasattr(os, "getgid"),
266271
"Missing getuid or getgid implementation")

0 commit comments

Comments
 (0)