[PATCH] files: report an error when the given filename ends in a slash

Benno Schulenberg <[email protected]> Mon, 8 Jun 2026 12:56:06 +0200
Newsgroups gmane.editors.nano.devel
Message-ID <[email protected]>
When the specified name (including the final slash) is not an existing
directory, then reject it as an invalid name -- instead of complaining
later, when the user tries to save the buffer, that the specified name
is a folder, which isn't actually true.

This addresses https://savannah.gnu.org/bugs/?68433.

Buglet existed since before version 2.0.0.
---
 src/files.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/files.c b/src/files.c
index 6d56a854..b0f855d8 100644
--- a/src/files.c
+++ b/src/files.c
@@ -425,6 +425,10 @@ bool open_buffer(const char *filename, bool new_one)
 		if (new_one && !(fileinfo.st_mode & (S_IWUSR|S_IWGRP|S_IWOTH)) && geteuid() == ROOT_UID)
 			statusline(ALERT, _("%s is meant to be read-only"), realname);
 #endif
+	} else if (*filename && filename[strlen(filename) - 1] == '/') {
+		statusline(ALERT, _("%s is an invalid name"), realname);
+		free(realname);
+		return FALSE;
 	}
 
 	/* When loading into a new buffer, first check the file's path is valid,
-- 
2.54.0