From 34b8d58871e3af5ef24d49c97e2d8d1c0e3b4599 Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <bensberg@telfort.nl>
Date: Sun, 30 Dec 2018 19:28:17 +0100
Subject: [PATCH] rcfile: reject an attempt to bind ^[

Also, for <Esc> <Esc> [, report that it is unbindable.

This fixes https://savannah.gnu.org/bugs/?55336.
---
 src/nano.c   | 4 +++-
 src/rcfile.c | 7 ++++---
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/nano.c b/src/nano.c
index ff4b9a27..263045bc 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -1568,7 +1568,9 @@ void unbound_key(int code)
 			statusline(ALERT, _("Unbindable key: M-["));
 		else
 			statusline(ALERT, _("Unbound key: M-%c"), toupper(code));
-	} else if (code < 0x20)
+	} else if (code == ESC_CODE)
+		statusline(ALERT, _("Unbindable key: ^["));
+	else if (code < 0x20)
 		statusline(ALERT, _("Unbound key: ^%c"), code + 0x40);
 	else
 		statusline(ALERT, _("Unbound key: %c"), code);
diff --git a/src/rcfile.c b/src/rcfile.c
index f588b7a3..581bae80 100644
--- a/src/rcfile.c
+++ b/src/rcfile.c
@@ -464,9 +464,10 @@ void parse_binding(char *ptr, bool dobind)
 	newsc->menus = menu;
 	assign_keyinfo(newsc, keycopy, 0);
 
-	/* Do not allow rebinding a frequent escape-sequence starter: Esc [. */
-	if (newsc->meta && newsc->keycode == 91) {
-		rcfile_error(N_("Sorry, keystroke \"%s\" may not be rebound"), newsc->keystr);
+	/* Disallow rebinding ^[ and frequent escape-sequence starter "Esc [". */
+	if ((!newsc->meta && newsc->keycode == ESC_CODE) ||
+				(newsc->meta && newsc->keycode == '[')) {
+		rcfile_error(N_("Keystroke %s may not be rebound"), keycopy);
   free_things:
 		free(keycopy);
 		free(newsc);
-- 
GitLab