aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/tarfile.py
diff options
context:
space:
mode:
authorChris Fernald <chrisf671@gmail.com>2022-06-17 15:38:41 -0700
committerGitHub <noreply@github.com>2022-06-17 15:38:41 -0700
commitc1e19421c23d1261ecbbe7375316adc1c24f0a87 (patch)
tree2917ef57beb68d70210a728238b477a27d1dbd64 /Lib/tarfile.py
parentb1ae4af5e82e7275cebcfb383690b816a388a785 (diff)
downloadcpython-c1e19421c23d1261ecbbe7375316adc1c24f0a87.tar.gz
cpython-c1e19421c23d1261ecbbe7375316adc1c24f0a87.zip
gh-91387: Strip trailing slash from tarfile longname directories (GH-32423)
Co-authored-by: Brett Cannon <brett@python.org>
Diffstat (limited to 'Lib/tarfile.py')
-rwxr-xr-xLib/tarfile.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/tarfile.py b/Lib/tarfile.py
index 8d43d0da7b9..169c88d63f7 100755
--- a/Lib/tarfile.py
+++ b/Lib/tarfile.py
@@ -1163,6 +1163,11 @@ class TarInfo(object):
# header information.
self._apply_pax_info(tarfile.pax_headers, tarfile.encoding, tarfile.errors)
+ # Remove redundant slashes from directories. This is to be consistent
+ # with frombuf().
+ if self.isdir():
+ self.name = self.name.rstrip("/")
+
return self
def _proc_gnulong(self, tarfile):
@@ -1185,6 +1190,11 @@ class TarInfo(object):
elif self.type == GNUTYPE_LONGLINK:
next.linkname = nts(buf, tarfile.encoding, tarfile.errors)
+ # Remove redundant slashes from directories. This is to be consistent
+ # with frombuf().
+ if next.isdir():
+ next.name = next.name.removesuffix("/")
+
return next
def _proc_sparse(self, tarfile):