bpo-1514420: Do not attempt to open files with names in <>s when form… · python/cpython@f71300c (original) (raw)

2 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 +Interpreter no longer attempts to open files with names in angle brackets (like "" or "") when formatting an exception.
Original file line number Diff line number Diff line change
@@ -396,6 +396,15 @@ _Py_DisplaySourceLine(PyObject *f, PyObject *filename, int lineno, int indent, i
396 396 if (filename == NULL)
397 397 return 0;
398 398
399 +/* Do not attempt to open things like or */
400 +assert(PyUnicode_Check(filename));
401 +if (PyUnicode_READ_CHAR(filename, 0) == '<') {
402 +Py_ssize_t len = PyUnicode_GET_LENGTH(filename);
403 +if (len > 0 && PyUnicode_READ_CHAR(filename, len - 1) == '>') {
404 +return 0;
405 + }
406 + }
407 +
399 408 io = PyImport_ImportModuleNoBlock("io");
400 409 if (io == NULL)
401 410 return -1;