Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8dcc48e

Browse files
committed
Issue #25758: Prevents zipimport from unnecessarily encoding a filename (patch by Eryk Sun)
1 parent 347dc95 commit 8dcc48e

3 files changed

Lines changed: 8 additions & 11 deletions

File tree

Lib/test/test_zipimport.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ def testUnencodable(self):
596596
z.writestr(zinfo, test_src)
597597
z.close()
598598
try:
599-
zipimport.zipimporter(filename)
599+
zipimport.zipimporter(filename).load_module(TESTMOD)
600600
finally:
601601
os.remove(filename)
602602

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Release date: TBA
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #25758: Prevents zipimport from unnecessarily encoding a filename
14+
(patch by Eryk Sun)
15+
1316
- Issue #27812: Properly clear out a generator's frame's backreference to the
1417
generator to prevent crashes in frame.clear().
1518

Modules/zipimport.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,22 +1362,16 @@ normalize_line_endings(PyObject *source)
13621362
static PyObject *
13631363
compile_source(PyObject *pathname, PyObject *source)
13641364
{
1365-
PyObject *code, *fixed_source, *pathbytes;
1366-
1367-
pathbytes = PyUnicode_EncodeFSDefault(pathname);
1368-
if (pathbytes == NULL)
1369-
return NULL;
1365+
PyObject *code, *fixed_source;
13701366

13711367
fixed_source = normalize_line_endings(source);
13721368
if (fixed_source == NULL) {
1373-
Py_DECREF(pathbytes);
13741369
return NULL;
13751370
}
13761371

1377-
code = Py_CompileString(PyBytes_AsString(fixed_source),
1378-
PyBytes_AsString(pathbytes),
1379-
Py_file_input);
1380-
Py_DECREF(pathbytes);
1372+
code = Py_CompileStringObject(PyBytes_AsString(fixed_source),
1373+
pathname, Py_file_input, NULL, 1);
1374+
13811375
Py_DECREF(fixed_source);
13821376
return code;
13831377
}

0 commit comments

Comments
 (0)