From 98f038ad96183ed4cca947180928d03002f87201 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Sun, 9 Feb 2020 11:41:56 +0100 Subject: [PATCH] rcfile: allow alternate line endings in nanorc files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When copy-pasting has resulted in a nanorc file with DOS line endings (CR+LF), then silently ignore the carriage return, to avoid printing an error message that partly overwrites itself. This fulfills https://savannah.gnu.org/bugs/?57756. Requested-by: Matthias Aßhauer --- src/rcfile.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/rcfile.c b/src/rcfile.c index 8fc105a2..a142a5ab 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -1317,9 +1317,11 @@ void parse_rcfile(FILE *rcstream, bool just_syntax, bool intros_only) if (just_syntax && !intros_only && lineno <= live_syntax->lineno) continue; #endif - /* Strip the terminating newline, if any. */ + /* Strip the terminating newline and possibly a carriage return. */ if (buffer[len - 1] == '\n') - buffer[len - 1] = '\0'; + buffer[--len] = '\0'; + if (buffer[len - 1] == '\r') + buffer[--len] = '\0'; ptr = buffer; while (isblank((unsigned char)*ptr))