diff options
author | Chris Fernald <chrisf671@gmail.com> | 2022-06-17 15:38:41 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-17 15:38:41 -0700 |
commit | c1e19421c23d1261ecbbe7375316adc1c24f0a87 (patch) | |
tree | 2917ef57beb68d70210a728238b477a27d1dbd64 /Lib/tarfile.py | |
parent | b1ae4af5e82e7275cebcfb383690b816a388a785 (diff) | |
download | cpython-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-x | Lib/tarfile.py | 10 |
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): |