-
-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Zip extraction UTF-8 handling for Python 2.7. (#2546)
Previously, zips with non-ASCII file names could cause extraction errors under Python 2.7 on Linux. Fixes #298
- Loading branch information
Showing
7 changed files
with
201 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright 2015 Pex project contributors. | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
__version__ = "2.20.1" | ||
__version__ = "2.20.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2024 Pex project contributors. | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from __future__ import absolute_import | ||
|
||
import os.path | ||
import shutil | ||
import subprocess | ||
from textwrap import dedent | ||
|
||
from pex.common import safe_open | ||
from pex.fetcher import URLFetcher | ||
from pex.typing import TYPE_CHECKING | ||
from testing.docker import skip_unless_docker | ||
|
||
if TYPE_CHECKING: | ||
from typing import Any | ||
|
||
|
||
@skip_unless_docker | ||
def test_confounding_encoding( | ||
tmpdir, # type: Any | ||
pex_project_dir, # type: str | ||
): | ||
# type: (...) -> None | ||
|
||
sdists = os.path.join(str(tmpdir), "sdists") | ||
with safe_open( | ||
os.path.join(sdists, "CherryPy-7.1.0.zip"), "wb" | ||
) as write_fp, URLFetcher().get_body_stream( | ||
"https://files.pythonhosted.org/packages/" | ||
"b7/dd/e95de2d7042bd53009e8673ca489effebd4a35d9b64b75ecfcca160efaf6/CherryPy-7.1.0.zip" | ||
) as read_fp: | ||
shutil.copyfileobj(read_fp, write_fp) | ||
|
||
dest = os.path.join(str(tmpdir), "dest") | ||
subprocess.check_call( | ||
args=[ | ||
"docker", | ||
"run", | ||
"--rm", | ||
"-v", | ||
"{code}:/code".format(code=pex_project_dir), | ||
"-w", | ||
"/code", | ||
"-v", | ||
"{sdists}:/sdists".format(sdists=sdists), | ||
"-v", | ||
"{dest}:/dest".format(dest=dest), | ||
"-e", | ||
"LANG=en_US.ISO-8859-1", | ||
"python:2.7-slim", | ||
"python2.7", | ||
"-c", | ||
dedent( | ||
"""\ | ||
from __future__ import absolute_import | ||
import os | ||
import zipfile | ||
from pex.common import open_zip | ||
with zipfile.ZipFile("/sdists/CherryPy-7.1.0.zip") as zf: | ||
try: | ||
zf.extractall("/dest") | ||
raise AssertionError( | ||
"Expected standard Python 2.7 ZipFile.extractall to fail." | ||
) | ||
except UnicodeEncodeError as e: | ||
pass | ||
with open_zip("/sdists/CherryPy-7.1.0.zip") as zf: | ||
zf.extractall("/dest") | ||
""" | ||
), | ||
] | ||
) | ||
|
||
assert os.path.isfile( | ||
os.path.join(dest, "CherryPy-7.1.0", "cherrypy", "test", "static", "Слава Україні.html") | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters