Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
672671da
Commit
672671da
authored
Feb 02, 2013
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Plain Diff
Fix the test for issue #6972.
Remove trailing dots on Windows.
parents
d357a3f8
e5e64444
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
6 deletions
+21
-6
Lib/test/test_zipfile.py
Lib/test/test_zipfile.py
+17
-5
Lib/zipfile.py
Lib/zipfile.py
+4
-1
No files found.
Lib/test/test_zipfile.py
View file @
672671da
...
@@ -548,8 +548,6 @@ class TestsWithSourceFile(unittest.TestCase):
...
@@ -548,8 +548,6 @@ class TestsWithSourceFile(unittest.TestCase):
(
'/foo/bar'
,
'foo/bar'
),
(
'/foo/bar'
,
'foo/bar'
),
(
'/foo/../bar'
,
'foo/bar'
),
(
'/foo/../bar'
,
'foo/bar'
),
(
'/foo/../../bar'
,
'foo/bar'
),
(
'/foo/../../bar'
,
'foo/bar'
),
(
'//foo/bar'
,
'foo/bar'
),
(
'../../foo../../ba..r'
,
'foo../ba..r'
),
]
]
if
os
.
path
.
sep
==
'
\
\
'
:
# Windows.
if
os
.
path
.
sep
==
'
\
\
'
:
# Windows.
hacknames
.
extend
([
hacknames
.
extend
([
...
@@ -571,19 +569,32 @@ class TestsWithSourceFile(unittest.TestCase):
...
@@ -571,19 +569,32 @@ class TestsWithSourceFile(unittest.TestCase):
(
r'\\?\
C:
\foo\bar'
,
'foo/bar'
),
(
r'\\?\
C:
\foo\bar'
,
'foo/bar'
),
(
r'C:/../C:/foo/bar'
,
'C_/foo/bar'
),
(
r'C:/../C:/foo/bar'
,
'C_/foo/bar'
),
(
r'a:b\
c<d>e|
f"g?h*i'
,
'b/c_d_e_f_g_h_i'
),
(
r'a:b\
c<d>e|
f"g?h*i'
,
'b/c_d_e_f_g_h_i'
),
(
'../../foo../../ba..r'
,
'foo/ba..r'
),
])
else
:
# Unix
hacknames
.
extend
([
(
'//foo/bar'
,
'foo/bar'
),
(
'../../foo../../ba..r'
,
'foo../ba..r'
),
(
r'foo/..\bar'
,
r'foo/..\bar'
),
])
])
for
arcname
,
fixedname
in
hacknames
:
for
arcname
,
fixedname
in
hacknames
:
content
=
b'foobar'
+
arcname
.
encode
()
content
=
b'foobar'
+
arcname
.
encode
()
with
zipfile
.
ZipFile
(
TESTFN2
,
'w'
,
zipfile
.
ZIP_STORED
)
as
zipfp
:
with
zipfile
.
ZipFile
(
TESTFN2
,
'w'
,
zipfile
.
ZIP_STORED
)
as
zipfp
:
zipfp
.
writestr
(
arcname
,
content
)
zinfo
=
zipfile
.
ZipInfo
()
# preserve backslashes
zinfo
.
filename
=
arcname
zinfo
.
external_attr
=
0o600
<<
16
zipfp
.
writestr
(
zinfo
,
content
)
arcname
=
arcname
.
replace
(
os
.
sep
,
"/"
)
targetpath
=
os
.
path
.
join
(
'target'
,
'subdir'
,
'subsub'
)
targetpath
=
os
.
path
.
join
(
'target'
,
'subdir'
,
'subsub'
)
correctfile
=
os
.
path
.
join
(
targetpath
,
*
fixedname
.
split
(
'/'
))
correctfile
=
os
.
path
.
join
(
targetpath
,
*
fixedname
.
split
(
'/'
))
with
zipfile
.
ZipFile
(
TESTFN2
,
'r'
)
as
zipfp
:
with
zipfile
.
ZipFile
(
TESTFN2
,
'r'
)
as
zipfp
:
writtenfile
=
zipfp
.
extract
(
arcname
,
targetpath
)
writtenfile
=
zipfp
.
extract
(
arcname
,
targetpath
)
self
.
assertEqual
(
writtenfile
,
correctfile
)
self
.
assertEqual
(
writtenfile
,
correctfile
,
msg
=
"extract %r"
%
arcname
)
self
.
check_file
(
correctfile
,
content
)
self
.
check_file
(
correctfile
,
content
)
shutil
.
rmtree
(
'target'
)
shutil
.
rmtree
(
'target'
)
...
@@ -596,7 +607,8 @@ class TestsWithSourceFile(unittest.TestCase):
...
@@ -596,7 +607,8 @@ class TestsWithSourceFile(unittest.TestCase):
with
zipfile
.
ZipFile
(
TESTFN2
,
'r'
)
as
zipfp
:
with
zipfile
.
ZipFile
(
TESTFN2
,
'r'
)
as
zipfp
:
writtenfile
=
zipfp
.
extract
(
arcname
)
writtenfile
=
zipfp
.
extract
(
arcname
)
self
.
assertEqual
(
writtenfile
,
correctfile
)
self
.
assertEqual
(
writtenfile
,
correctfile
,
msg
=
"extract %r"
%
arcname
)
self
.
check_file
(
correctfile
,
content
)
self
.
check_file
(
correctfile
,
content
)
shutil
.
rmtree
(
fixedname
.
split
(
'/'
)[
0
])
shutil
.
rmtree
(
fixedname
.
split
(
'/'
)[
0
])
...
...
Lib/zipfile.py
View file @
672671da
...
@@ -1238,11 +1238,14 @@ class ZipFile:
...
@@ -1238,11 +1238,14 @@ class ZipFile:
arcname
=
os
.
path
.
splitdrive
(
arcname
)[
1
]
arcname
=
os
.
path
.
splitdrive
(
arcname
)[
1
]
arcname
=
os
.
path
.
sep
.
join
(
x
for
x
in
arcname
.
split
(
os
.
path
.
sep
)
arcname
=
os
.
path
.
sep
.
join
(
x
for
x
in
arcname
.
split
(
os
.
path
.
sep
)
if
x
not
in
(
''
,
os
.
path
.
curdir
,
os
.
path
.
pardir
))
if
x
not
in
(
''
,
os
.
path
.
curdir
,
os
.
path
.
pardir
))
# filter illegal characters on Windows
if
os
.
path
.
sep
==
'
\
\
'
:
if
os
.
path
.
sep
==
'
\
\
'
:
# filter illegal characters on Windows
illegal
=
':<>|"?*'
illegal
=
':<>|"?*'
table
=
str
.
maketrans
(
illegal
,
'_'
*
len
(
illegal
))
table
=
str
.
maketrans
(
illegal
,
'_'
*
len
(
illegal
))
arcname
=
arcname
.
translate
(
table
)
arcname
=
arcname
.
translate
(
table
)
# remove trailing dots
arcname
=
(
x
.
rstrip
(
'.'
)
for
x
in
arcname
.
split
(
os
.
path
.
sep
))
arcname
=
os
.
path
.
sep
.
join
(
x
for
x
in
arcname
if
x
)
targetpath
=
os
.
path
.
join
(
targetpath
,
arcname
)
targetpath
=
os
.
path
.
join
(
targetpath
,
arcname
)
targetpath
=
os
.
path
.
normpath
(
targetpath
)
targetpath
=
os
.
path
.
normpath
(
targetpath
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment