summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@microsoft.com>2016-09-10 00:27:33 (GMT)
committerSteve Dower <steve.dower@microsoft.com>2016-09-10 00:27:33 (GMT)
commit8dcc48ee3b6447cd63038e63ee11de36f6d85a68 (patch)
tree263c7533f46fd87624671678ebb5bffce4501753
parent347dc95cd3b2d5d00a6d1a378084d87d32a47ab0 (diff)
downloadcpython-8dcc48ee3b6447cd63038e63ee11de36f6d85a68.zip
cpython-8dcc48ee3b6447cd63038e63ee11de36f6d85a68.tar.gz
cpython-8dcc48ee3b6447cd63038e63ee11de36f6d85a68.tar.bz2
Issue #25758: Prevents zipimport from unnecessarily encoding a filename (patch by Eryk Sun)
-rw-r--r--Lib/test/test_zipimport.py2
-rw-r--r--Misc/NEWS3
-rw-r--r--Modules/zipimport.c14
3 files changed, 8 insertions, 11 deletions
diff --git a/Lib/test/test_zipimport.py b/Lib/test/test_zipimport.py
index 8e5e12d..2bb7230 100644
--- a/Lib/test/test_zipimport.py
+++ b/Lib/test/test_zipimport.py
@@ -596,7 +596,7 @@ class UncompressedZipImportTestCase(ImportHooksBaseTestCase):
z.writestr(zinfo, test_src)
z.close()
try:
- zipimport.zipimporter(filename)
+ zipimport.zipimporter(filename).load_module(TESTMOD)
finally:
os.remove(filename)
diff --git a/Misc/NEWS b/Misc/NEWS
index 6ef92f7..c1420e1 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ Release date: TBA
Core and Builtins
-----------------
+- Issue #25758: Prevents zipimport from unnecessarily encoding a filename
+ (patch by Eryk Sun)
+
- Issue #27812: Properly clear out a generator's frame's backreference to the
generator to prevent crashes in frame.clear().
diff --git a/Modules/zipimport.c b/Modules/zipimport.c
index 6d5c68a..92a82e6 100644
--- a/Modules/zipimport.c
+++ b/Modules/zipimport.c
@@ -1362,22 +1362,16 @@ normalize_line_endings(PyObject *source)
static PyObject *
compile_source(PyObject *pathname, PyObject *source)
{
- PyObject *code, *fixed_source, *pathbytes;
-
- pathbytes = PyUnicode_EncodeFSDefault(pathname);
- if (pathbytes == NULL)
- return NULL;
+ PyObject *code, *fixed_source;
fixed_source = normalize_line_endings(source);
if (fixed_source == NULL) {
- Py_DECREF(pathbytes);
return NULL;
}
- code = Py_CompileString(PyBytes_AsString(fixed_source),
- PyBytes_AsString(pathbytes),
- Py_file_input);
- Py_DECREF(pathbytes);
+ code = Py_CompileStringObject(PyBytes_AsString(fixed_source),
+ pathname, Py_file_input, NULL, 1);
+
Py_DECREF(fixed_source);
return code;
}