Michael Felt <[email protected]> added the comment:
OK - issue17324 (not 1 7 2 3 4)
And, as jkloth reported that Windows also has an issue - sometimes, found a way
to do this in Modules/_io/fileio.c
diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c
index c0e43e0ae4..3623ff16ea 100644
--- a/Modules/_io/fileio.c
+++ b/Modules/_io/fileio.c
@@ -228,6 +228,7 @@ _io_FileIO___init___impl(fileio *self, PyObject *nameobj,
const char *mode,
#endif
PyObject *stringobj = NULL;
const char *s;
+ char *rcpt;
int ret = 0;
int rwa = 0, plus = 0;
int flags = 0;
@@ -447,6 +448,23 @@ _io_FileIO___init___impl(fileio *self, PyObject *nameobj,
const char *mode,
}
}
else {
+#if defined(S_ISREG) && defined(ENOTDIR)
+ /* On AIX and Windows, open may succeed for files with a trailing
slash.
+ The Open Group specifies filenames ending with a trailing slash
should
+ be an error - ENOTDIR */
+ if (S_ISREG(fdfstat.st_mode)) {
+#ifdef MS_WINDOWS
+ rcpt= strrch(widename, '\');
+#else
+ rcpt = strrchr(name, '/');
+#endif
+ if ((rcpt != NULL) && (strlen(rcpt) == 1)) {
+ errno = ENOTDIR;
+ PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError,
nameobj);
+ goto error;
+ }
+ }
+#endif
#if defined(S_ISDIR) && defined(EISDIR)
/* On Unix, open will succeed for directories.
In Python, there should be no file objects referring to
And, now for the PR tests...
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue34711>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com