Author Michael.Felt
Recipients Michael.Felt, jkloth
Date 2018-09-17.14:00:47
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1537192847.87.0.956365154283.issue34711@psf.upfronthosting.co.za>
In-reply-to
Content
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...
History
Date User Action Args
2018-09-17 14:00:47Michael.Feltsetrecipients: + Michael.Felt, jkloth
2018-09-17 14:00:47Michael.Feltsetmessageid: <1537192847.87.0.956365154283.issue34711@psf.upfronthosting.co.za>
2018-09-17 14:00:47Michael.Feltlinkissue34711 messages
2018-09-17 14:00:47Michael.Feltcreate