diff options
author | Christian Heimes <christian@cheimes.de> | 2007-11-07 17:26:16 (GMT) |
---|---|---|
committer | Christian Heimes <christian@cheimes.de> | 2007-11-07 17:26:16 (GMT) |
commit | 7d3bc0ade62ed38b26be03f408ad99f8fe290b5b (patch) | |
tree | b7cbbf94b6088512b9910787c351d39ef2604b76 /Python | |
parent | ef181a7619a84639fed79d3071703636f39c3485 (diff) | |
download | cpython-7d3bc0ade62ed38b26be03f408ad99f8fe290b5b.zip cpython-7d3bc0ade62ed38b26be03f408ad99f8fe290b5b.tar.gz cpython-7d3bc0ade62ed38b26be03f408ad99f8fe290b5b.tar.bz2 |
Patch for bug http://bugs.python.org/issue1293
The patch doesn't do the whole name mangling mambo jambo on purpose. MS sure does some weird things and I don't feel like reimplementing ntpath.normpath in C. If the user does deliberately something stupid he is on his own.
TODO: Backport to 2.6 (maybe 2.5?) and document that users should only do sys.path.append(os.path.normpath(somepath)) if they want to be on the safe side.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/import.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/Python/import.c b/Python/import.c index 289a1fb..d2922e9 100644 --- a/Python/import.c +++ b/Python/import.c @@ -2922,6 +2922,7 @@ static int NullImporter_init(NullImporter *self, PyObject *args, PyObject *kwds) { char *path; + Py_ssize_t pathlen; if (!_PyArg_NoKeywords("NullImporter()", kwds)) return -1; @@ -2930,14 +2931,31 @@ NullImporter_init(NullImporter *self, PyObject *args, PyObject *kwds) &path)) return -1; - if (strlen(path) == 0) { + pathlen = strlen(path); + if (pathlen == 0) { PyErr_SetString(PyExc_ImportError, "empty pathname"); return -1; } else { struct stat statbuf; int rv; +#ifdef MS_WINDOWS + /* MS Windows' stat chokes on paths like C:\\path\\. Try to + * recover *one* time by stripping of a trailing slash or + * back slash. http://bugs.python.org/issue1293 + */ rv = stat(path, &statbuf); + if (rv != 0 && pathlen <= MAXPATHLEN && + (path[pathlen-1] == '/' || path[pathlen-1] == '\\')) { + char mangled[MAXPATHLEN+1]; + + strcpy(mangled, path); + mangled[pathlen-1] = '\0'; + rv = stat(mangled, &statbuf); + } +#else + rv = stat(path, &statbuf); +#endif if (rv == 0) { /* it exists */ if (S_ISDIR(statbuf.st_mode)) { |