@@ -3682,6 +3682,39 @@ class TestExtractionFilters(unittest.TestCase):
36823682 # The destination for the extraction, within `outerdir`
36833683 destdir = outerdir / 'dest'
36843684
3685+ @classmethod
3686+ def setUpClass (cls ):
3687+ # Posix and Windows have different pathname resolution:
3688+ # either symlink or a '..' component resolve first.
3689+ # Let's see which we are on.
3690+ if os_helper .can_symlink ():
3691+ testpath = os .path .join (TEMPDIR , 'resolution_test' )
3692+ os .mkdir (testpath )
3693+
3694+ # testpath/current links to `.` which is all of:
3695+ # - `testpath`
3696+ # - `testpath/current`
3697+ # - `testpath/current/current`
3698+ # - etc.
3699+ os .symlink ('.' , os .path .join (testpath , 'current' ))
3700+
3701+ # we'll test where `testpath/current/../file` ends up
3702+ with open (os .path .join (testpath , 'current' , '..' , 'file' ), 'w' ):
3703+ pass
3704+
3705+ if os .path .exists (os .path .join (testpath , 'file' )):
3706+ # Windows collapses 'current\..' to '.' first, leaving
3707+ # 'testpath\file'
3708+ cls .dotdot_resolves_early = True
3709+ elif os .path .exists (os .path .join (testpath , '..' , 'file' )):
3710+ # Posix resolves 'current' to '.' first, leaving
3711+ # 'testpath/../file'
3712+ cls .dotdot_resolves_early = False
3713+ else :
3714+ raise AssertionError ('Could not determine link resolution' )
3715+ else :
3716+ cls .dotdot_resolves_early = False
3717+
36853718 @contextmanager
36863719 def check_context (self , tar , filter , * , check_flag = True ):
36873720 """Extracts `tar` to `self.destdir` and allows checking the result
@@ -3955,35 +3988,6 @@ def test_parent_symlink2(self):
39553988 # Test interplaying symlinks
39563989 # Inspired by 'dirsymlink2b' in jwilk/traversal-archives
39573990
3958- # Posix and Windows have different pathname resolution:
3959- # either symlink or a '..' component resolve first.
3960- # Let's see which we are on.
3961- if os_helper .can_symlink ():
3962- testpath = os .path .join (TEMPDIR , 'resolution_test' )
3963- os .mkdir (testpath )
3964-
3965- # testpath/current links to `.` which is all of:
3966- # - `testpath`
3967- # - `testpath/current`
3968- # - `testpath/current/current`
3969- # - etc.
3970- os .symlink ('.' , os .path .join (testpath , 'current' ))
3971-
3972- # we'll test where `testpath/current/../file` ends up
3973- with open (os .path .join (testpath , 'current' , '..' , 'file' ), 'w' ):
3974- pass
3975-
3976- if os .path .exists (os .path .join (testpath , 'file' )):
3977- # Windows collapses 'current\..' to '.' first, leaving
3978- # 'testpath\file'
3979- dotdot_resolves_early = True
3980- elif os .path .exists (os .path .join (testpath , '..' , 'file' )):
3981- # Posix resolves 'current' to '.' first, leaving
3982- # 'testpath/../file'
3983- dotdot_resolves_early = False
3984- else :
3985- raise AssertionError ('Could not determine link resolution' )
3986-
39873991 with ArchiveMaker () as arc :
39883992
39893993 # `current` links to `.` which is both the destination directory
@@ -4019,7 +4023,7 @@ def test_parent_symlink2(self):
40194023
40204024 with self .check_context (arc .open (), 'data' ):
40214025 if os_helper .can_symlink ():
4022- if dotdot_resolves_early :
4026+ if self . dotdot_resolves_early :
40234027 # Fail when extracting a file outside destination
40244028 self .expect_exception (
40254029 tarfile .OutsideDestinationError ,
0 commit comments