aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/parser.c
diff options
context:
space:
mode:
authorRobin Haberkorn <rhaberkorn@fmsbw.de>2026-08-09 13:52:37 +0200
committerRobin Haberkorn <rhaberkorn@fmsbw.de>2026-08-10 23:55:40 +0200
commit822b93aa765c7497b617ead419357f1be09e9ab0 (patch)
tree40bd544ed57f27dc597735a89a1049417a2170ef /src/parser.c
parent573c9d9b60e2c4dca2be6ccd43ac92b8725f4453 (diff)
when inserting text after auto completions, escape all magic string building characters
This fixes insertion of strings containing ^, ^P, ^Q, ^R, ^V, ^W, ^E. It mainly affects Q-Register specification auto-completions, but filenames could theoretically also contain such special characters.
Diffstat (limited to 'src/parser.c')
-rw-r--r--src/parser.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/parser.c b/src/parser.c
index 32e60cd..8b02764 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -1023,9 +1023,11 @@ teco_machine_stringbuilding_reset(teco_machine_stringbuilding_t *ctx)
ctx->mode = TECO_STRINGBUILDING_MODE_NORMAL;
}
-/*
- * If we case folded only ANSI characters as in teco_ascii_toupper(),
- * this could be simplified.
+/**
+ * Escape string so it can be inserted into a command's string argument
+ * or Q-Register specification.
+ *
+ * This is used for auto-completions and when clicking into auto-completion popups.
*/
void
teco_machine_stringbuilding_escape(teco_machine_stringbuilding_t *ctx, const gchar *str, gsize len,
@@ -1038,13 +1040,18 @@ teco_machine_stringbuilding_escape(teco_machine_stringbuilding_t *ctx, const gch
gunichar chr = g_utf8_get_char(str+i);
/*
+ * If we case folded only ANSI characters as in teco_ascii_toupper(),
+ * this could be simplified.
+ *
* NOTE: We support both `[` and `{`, so this works for autocompleting
* long Q-register specifications as well.
* This may therefore insert unnecessary ^Q, but they won't hurt.
*/
if (g_unichar_toupper(chr) == ctx->escape_char ||
(ctx->escape_char == '[' && chr == ']') ||
- (ctx->escape_char == '{' && chr == '}'))
+ (ctx->escape_char == '{' && chr == '}') ||
+ /* magic characters: ^P, ^Q, ^R, ^V, ^W, ^E */
+ (chr != TECO_CTL_KEY('@') && strchr("^\x10\x11\x12\x16\x17\x05", chr)))
target->data[target->len++] = TECO_CTL_KEY('Q');
gsize lenc = g_utf8_next_char(str+i) - (str+i);