diff options
author | Lars Gustäbel <lars@gustaebel.de> | 2009-08-28 19:59:59 (GMT) |
---|---|---|
committer | Lars Gustäbel <lars@gustaebel.de> | 2009-08-28 19:59:59 (GMT) |
commit | bfdfdda1067ae32f72040a0b6aefa5807e41da51 (patch) | |
tree | 3a38857be9246ebb0b23a3560217a376990f4761 /Lib/test/test_tarfile.py | |
parent | d314e1b9291544640a9a85542b335d692a9576b6 (diff) | |
download | cpython-bfdfdda1067ae32f72040a0b6aefa5807e41da51.zip cpython-bfdfdda1067ae32f72040a0b6aefa5807e41da51.tar.gz cpython-bfdfdda1067ae32f72040a0b6aefa5807e41da51.tar.bz2 |
Merged revisions 74571 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r74571 | lars.gustaebel | 2009-08-28 21:23:44 +0200 (Fri, 28 Aug 2009) | 7 lines
Issue #6054: Do not normalize stored pathnames.
No longer use tarfile.normpath() on pathnames. Store pathnames
unchanged, i.e. do not remove "./", "../" and "//" occurrences.
However, still convert absolute to relative paths.
........
Diffstat (limited to 'Lib/test/test_tarfile.py')
-rw-r--r-- | Lib/test/test_tarfile.py | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index 76390c7..83f4a8c 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -659,6 +659,76 @@ class WriteTest(WriteTestBase): finally: shutil.rmtree(tempdir) + # Guarantee that stored pathnames are not modified. Don't + # remove ./ or ../ or double slashes. Still make absolute + # pathnames relative. + # For details see bug #6054. + def _test_pathname(self, path, cmp_path=None, dir=False): + # Create a tarfile with an empty member named path + # and compare the stored name with the original. + foo = os.path.join(TEMPDIR, "foo") + if not dir: + open(foo, "w").close() + else: + os.mkdir(foo) + + tar = tarfile.open(tmpname, self.mode) + tar.add(foo, arcname=path) + tar.close() + + tar = tarfile.open(tmpname, "r") + t = tar.next() + tar.close() + + if not dir: + os.remove(foo) + else: + os.rmdir(foo) + + self.assertEqual(t.name, cmp_path or path.replace(os.sep, "/")) + + def test_pathnames(self): + self._test_pathname("foo") + self._test_pathname(os.path.join("foo", ".", "bar")) + self._test_pathname(os.path.join("foo", "..", "bar")) + self._test_pathname(os.path.join(".", "foo")) + self._test_pathname(os.path.join(".", "foo", ".")) + self._test_pathname(os.path.join(".", "foo", ".", "bar")) + self._test_pathname(os.path.join(".", "foo", "..", "bar")) + self._test_pathname(os.path.join(".", "foo", "..", "bar")) + self._test_pathname(os.path.join("..", "foo")) + self._test_pathname(os.path.join("..", "foo", "..")) + self._test_pathname(os.path.join("..", "foo", ".", "bar")) + self._test_pathname(os.path.join("..", "foo", "..", "bar")) + + self._test_pathname("foo" + os.sep + os.sep + "bar") + self._test_pathname("foo" + os.sep + os.sep, "foo", dir=True) + + def test_abs_pathnames(self): + if sys.platform == "win32": + self._test_pathname("C:\\foo", "foo") + else: + self._test_pathname("/foo", "foo") + self._test_pathname("///foo", "foo") + + def test_cwd(self): + # Test adding the current working directory. + cwd = os.getcwd() + os.chdir(TEMPDIR) + try: + open("foo", "w").close() + + tar = tarfile.open(tmpname, self.mode) + tar.add(".") + tar.close() + + tar = tarfile.open(tmpname, "r") + for t in tar: + self.assert_(t.name == "." or t.name.startswith("./")) + tar.close() + finally: + os.chdir(cwd) + class StreamWriteTest(WriteTestBase): |