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
108a7a31
Commit
108a7a31
authored
Apr 13, 2013
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #17656: Fix extraction of zip files with unicode member paths.
parent
4ac42666
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
2 deletions
+26
-2
Lib/test/test_zipfile.py
Lib/test/test_zipfile.py
+20
-1
Lib/zipfile.py
Lib/zipfile.py
+4
-1
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/test/test_zipfile.py
View file @
108a7a31
...
...
@@ -18,7 +18,7 @@ from tempfile import TemporaryFile
from
random
import
randint
,
random
from
unittest
import
skipUnless
from
test.test_support
import
TESTFN
,
run_unittest
,
findfile
,
unlink
from
test.test_support
import
TESTFN
,
TESTFN_UNICODE
,
run_unittest
,
findfile
,
unlink
TESTFN2
=
TESTFN
+
"2"
TESTFNDIR
=
TESTFN
+
"d"
...
...
@@ -424,6 +424,25 @@ class TestsWithSourceFile(unittest.TestCase):
with
open
(
filename
,
'rb'
)
as
f
:
self
.
assertEqual
(
f
.
read
(),
content
)
def
test_extract_unicode_filenames
(
self
):
fnames
=
[
u'foo.txt'
,
os
.
path
.
basename
(
TESTFN_UNICODE
)]
content
=
'Test for unicode filename'
with
zipfile
.
ZipFile
(
TESTFN2
,
"w"
,
zipfile
.
ZIP_STORED
)
as
zipfp
:
for
fname
in
fnames
:
zipfp
.
writestr
(
fname
,
content
)
with
zipfile
.
ZipFile
(
TESTFN2
,
"r"
)
as
zipfp
:
for
fname
in
fnames
:
writtenfile
=
zipfp
.
extract
(
fname
)
# make sure it was written to the right place
correctfile
=
os
.
path
.
join
(
os
.
getcwd
(),
fname
)
correctfile
=
os
.
path
.
normpath
(
correctfile
)
self
.
assertEqual
(
writtenfile
,
correctfile
)
self
.
check_file
(
writtenfile
,
content
)
os
.
remove
(
writtenfile
)
def
test_extract_hackers_arcnames
(
self
):
hacknames
=
[
(
'../foo/bar'
,
'foo/bar'
),
...
...
Lib/zipfile.py
View file @
108a7a31
...
...
@@ -1053,7 +1053,10 @@ class ZipFile(object):
if
os
.
path
.
sep
==
'
\
\
'
:
# filter illegal characters on Windows
illegal
=
':<>|"?*'
table
=
string
.
maketrans
(
illegal
,
'_'
*
len
(
illegal
))
if
isinstance
(
arcname
,
unicode
):
table
=
{
ord
(
c
):
ord
(
'_'
)
for
c
in
illegal
}
else
:
table
=
string
.
maketrans
(
illegal
,
'_'
*
len
(
illegal
))
arcname
=
arcname
.
translate
(
table
)
# remove trailing dots
arcname
=
(
x
.
rstrip
(
'.'
)
for
x
in
arcname
.
split
(
os
.
path
.
sep
))
...
...
Misc/NEWS
View file @
108a7a31
...
...
@@ -22,6 +22,8 @@ Core and Builtins
Library
-------
-
Issue
#
17656
:
Fix
extraction
of
zip
files
with
unicode
member
paths
.
-
Issue
#
13355
:
Raise
ValueError
on
random
.
triangular
call
with
invalid
params
.
Initial
patch
by
Yuriy
Senko
.
...
...
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