Treat plausible but invalid keys (like C-BSpace) as literal like any

other unrecognised string passed to send-keys. Reported by Anthony
Sottile in GitHub issue 2049.
This commit is contained in:
nicm
2020-01-13 07:51:54 +00:00
parent 381333c4a9
commit 04eee2410d
4 changed files with 30 additions and 19 deletions

View File

@ -150,7 +150,7 @@ input_split2(u_int c, u_char *dst)
}
/* Translate a key code into an output key sequence. */
void
int
input_key(struct window_pane *wp, key_code key, struct mouse_event *m)
{
const struct input_key_ent *ike;
@ -167,14 +167,14 @@ input_key(struct window_pane *wp, key_code key, struct mouse_event *m)
if (KEYC_IS_MOUSE(key)) {
if (m != NULL && m->wp != -1 && (u_int)m->wp == wp->id)
input_key_mouse(wp, m);
return;
return (0);
}
/* Literal keys go as themselves (can't be more than eight bits). */
if (key & KEYC_LITERAL) {
ud.data[0] = (u_char)key;
bufferevent_write(wp->event, &ud.data[0], 1);
return;
return (0);
}
/* Is this backspace? */
@ -195,15 +195,15 @@ input_key(struct window_pane *wp, key_code key, struct mouse_event *m)
bufferevent_write(wp->event, "\033", 1);
ud.data[0] = justkey;
bufferevent_write(wp->event, &ud.data[0], 1);
return;
return (0);
}
if (justkey > 0x7f && justkey < KEYC_BASE) {
if (utf8_split(justkey, &ud) != UTF8_DONE)
return;
return (-1);
if (key & KEYC_ESCAPE)
bufferevent_write(wp->event, "\033", 1);
bufferevent_write(wp->event, ud.data, ud.size);
return;
return (0);
}
/*
@ -214,7 +214,7 @@ input_key(struct window_pane *wp, key_code key, struct mouse_event *m)
if ((out = xterm_keys_lookup(key)) != NULL) {
bufferevent_write(wp->event, out, strlen(out));
free(out);
return;
return (0);
}
}
key &= ~KEYC_XTERM;
@ -237,7 +237,7 @@ input_key(struct window_pane *wp, key_code key, struct mouse_event *m)
}
if (i == nitems(input_keys)) {
log_debug("key 0x%llx missing", key);
return;
return (-1);
}
dlen = strlen(ike->data);
log_debug("found key 0x%llx: \"%s\"", key, ike->data);
@ -246,6 +246,7 @@ input_key(struct window_pane *wp, key_code key, struct mouse_event *m)
if (key & KEYC_ESCAPE)
bufferevent_write(wp->event, "\033", 1);
bufferevent_write(wp->event, ike->data, dlen);
return (0);
}
/* Translate mouse and output. */