From 22cd25d36059c784ea0da3ebeed063414aad44d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Mon, 27 Jul 2020 06:03:30 +0200 Subject: [PATCH 1/6] tokenize: reset *argv = NULL on error This allows the caller to call free() without having to worry about whether it has already been free:d or not. Closes #49. --- tokenize.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tokenize.c b/tokenize.c index b4aab6b5..703ecb07 100644 --- a/tokenize.c +++ b/tokenize.c @@ -46,6 +46,7 @@ tokenize_cmdline(char *cmdline, char ***argv) if (delim != ' ') { LOG_ERR("unterminated %s quote\n", delim == '"' ? "double" : "single"); free(*argv); + *argv = NULL; return false; } From a9eeeedc90224cb74b6d265c91c1a60fa884254c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Mon, 27 Jul 2020 06:04:29 +0200 Subject: [PATCH 2/6] tokenize: remove newline from log message (LOG_ERR appends one for us) --- tokenize.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tokenize.c b/tokenize.c index 703ecb07..2671e23b 100644 --- a/tokenize.c +++ b/tokenize.c @@ -44,7 +44,7 @@ tokenize_cmdline(char *cmdline, char ***argv) char *end = strchr(p, delim); if (end == NULL) { if (delim != ' ') { - LOG_ERR("unterminated %s quote\n", delim == '"' ? "double" : "single"); + LOG_ERR("unterminated %s quote", delim == '"' ? "double" : "single"); free(*argv); *argv = NULL; return false; From faad0936270171467546c920e8cb629c0aa69efc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Mon, 27 Jul 2020 16:41:35 +0200 Subject: [PATCH 3/6] changelog: mention fix for crash on unclosed quote in tokenizer --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index df304262..d4836891 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,9 @@ ### Fixed * Crash in scrollback search +* Crash when a **pipe-visible** or **pipe-scrollback** command + contained an unclosed quote + (https://codeberg.org/dnkl/foot/issues/49). ### Security From 50bd51c4d43931418c5b8c706841b46b67c1a947 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Mon, 27 Jul 2020 16:43:41 +0200 Subject: [PATCH 4/6] tokenize: handle escaped quotes We only support escaping quotes inside a quote, and only of the same type as the enclosing quote. I.e. "double quote \"escaped double quote\"" But not "double quote \'invalid escaped single quote\'" --- CHANGELOG.md | 2 ++ tokenize.c | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d4836891..764e8f46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ * [LICENSE](LICENSE), [README.md](README.md) and [CHANGELOG.md](CHANGELOG.md) are now installed to `${datadir}/doc/foot`. +* Support for escaping quotes in **pipe-visible** and + **pipe-scrollback** commands. ### Changed diff --git a/tokenize.c b/tokenize.c index 2671e23b..35d52345 100644 --- a/tokenize.c +++ b/tokenize.c @@ -38,10 +38,11 @@ tokenize_cmdline(char *cmdline, char ***argv) char delim = first_token_is_quoted ? cmdline[0] : ' '; char *p = first_token_is_quoted ? &cmdline[1] : &cmdline[0]; + char *search_start = p; size_t idx = 0; while (*p != '\0') { - char *end = strchr(p, delim); + char *end = strchr(search_start, delim); if (end == NULL) { if (delim != ' ') { LOG_ERR("unterminated %s quote", delim == '"' ? "double" : "single"); @@ -58,6 +59,15 @@ tokenize_cmdline(char *cmdline, char ***argv) return true; } + if (end > p && *(end - 1) == '\\') { + /* Escaped quote, remove one level of escaping and + * continue searching for "our" closing quote */ + memmove(end - 1, end, strlen(end)); + end[strlen(end) - 1] = '\0'; + search_start = end; + continue; + } + *end = '\0'; if (!push_argv(argv, &argv_size, p, &idx)) @@ -75,6 +85,7 @@ tokenize_cmdline(char *cmdline, char ***argv) p++; } else delim = ' '; + search_start = p; } if (!push_argv(argv, &argv_size, NULL, &idx)) From 7127a0a6c393ee888a7b640c5481e191e0744519 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Mon, 27 Jul 2020 16:44:41 +0200 Subject: [PATCH 5/6] selection: extending a selection is now interactive That is, a selection extension can be resized just like an ordinary extension. --- CHANGELOG.md | 4 +++- input.c | 2 +- selection.c | 16 ++++++++-------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 764e8f46..53c2462a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,13 +37,15 @@ outside it. * Scrollback search to focus match, that requires a viewport change, roughly in the center of the screen. +* Extending a selection with the right mouse button now works while + dragging the mouse. ### Deprecated ### Removed ### Fixed -* Crash in scrollback search +* Crash in scrollback search. * Crash when a **pipe-visible** or **pipe-scrollback** command contained an unclosed quote (https://codeberg.org/dnkl/foot/issues/49). diff --git a/input.c b/input.c index 442cd322..c7f4b073 100644 --- a/input.c +++ b/input.c @@ -1171,7 +1171,7 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, if (col < 0 || row < 0 || col >= term->cols || row >= term->rows) return; - bool update_selection = seat->mouse.button == BTN_LEFT; + bool update_selection = seat->mouse.button == BTN_LEFT || seat->mouse.button == BTN_RIGHT; bool update_selection_early = term->selection.end.row == -1; if (update_selection && update_selection_early) diff --git a/selection.c b/selection.c index d5add464..354f6f53 100644 --- a/selection.c +++ b/selection.c @@ -372,8 +372,8 @@ selection_extend_normal(struct terminal *term, int col, int row, uint32_t serial if (row < start->row || (row == start->row && col < start->col)) { /* Extend selection to start *before* current start */ - new_start = (struct coord){col, row}; - new_end = *end; + new_start = *end; + new_end = (struct coord){col, row}; } else if (row > end->row || (row == end->row && col > end->col)) { @@ -391,8 +391,8 @@ selection_extend_normal(struct terminal *term, int col, int row, uint32_t serial abs(linear - (end->row * term->cols + end->col))) { /* Move start point */ - new_start = (struct coord){col, row}; - new_end = *end; + new_start = *end; + new_end = (struct coord){col, row}; } else { @@ -440,13 +440,13 @@ selection_extend_block(struct terminal *term, int col, int row, uint32_t serial) /* Move one of the top corners */ if (abs(col - top_left.col) < abs(col - top_right.col)) { - new_start = (struct coord){col, row}; - new_end = bottom_right; + new_start = bottom_right; + new_end = (struct coord){col, row}; } else { - new_start = (struct coord){col, row}; - new_end = bottom_left; + new_start = bottom_left; + new_end = (struct coord){col, row}; } } From 77afd615251ebff7b090454c180a5f5470cb97e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Mon, 27 Jul 2020 16:45:34 +0200 Subject: [PATCH 6/6] doc: foot.5: modifiers+keys are plural --- doc/foot.5.scd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/foot.5.scd b/doc/foot.5.scd index 7c3ab283..d837cd1a 100644 --- a/doc/foot.5.scd +++ b/doc/foot.5.scd @@ -176,7 +176,7 @@ This section lets you override the default key bindings. The general format is _action=combo1...comboN_. That is, each action may have one or more key combinations, space separated. Each combination is on the form _mod1+mod2+key_. The names of the modifiers -and the key *must* be a valid XKB key name. +and the key *must* be valid XKB key names. Note that if *Shift* is one of the modifiers, the _key_ *must* be in upper case. For example, *Control+Shift+v* will never trigger -