aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorRobin Haberkorn <rhaberkorn@fmsbw.de>2026-01-18 21:36:56 +0100
committerRobin Haberkorn <rhaberkorn@fmsbw.de>2026-01-18 21:36:56 +0100
commit3deb2b3970cb344d0c615e9d41a5fe7f3baf1417 (patch)
tree144aa3f120d4276aa5d15496c8927ed050350af7 /src
parentb5dac044ddda2d2057d1d785d5827c1b890c90b6 (diff)
fixed auto-completion of Unicode file names
* teco_string_diff() could return a number of bytes in the middle of an Unicode sequence. It now also requires Unicode strings. * Added a missing Unicode-validity check when replacing command lines (`{` and `}`). teco_cmdline_insert() should really be refactored, though (FIXME). * Added test case
Diffstat (limited to 'src')
-rw-r--r--src/cmdline.c24
-rw-r--r--src/string-utils.c10
2 files changed, 28 insertions, 6 deletions
diff --git a/src/cmdline.c b/src/cmdline.c
index fa69d91..9a7b356 100644
--- a/src/cmdline.c
+++ b/src/cmdline.c
@@ -162,12 +162,32 @@ teco_cmdline_insert(const gchar *data, gsize len, GError **error)
* Result of command line replacement (}):
* Exchange command lines
*/
+ g_clear_error(&tmp_error);
+
teco_qreg_t *cmdline_reg = teco_qreg_table_find(&teco_qreg_table_globals, "\e", 1);
g_auto(teco_string_t) new_cmdline = {NULL, 0};
if (!cmdline_reg->vtable->get_string(cmdline_reg, &new_cmdline.data, &new_cmdline.len,
- NULL, error))
+ NULL, &tmp_error)) {
+ teco_error_add_frame_toplevel();
+ teco_error_display_short(tmp_error);
+ g_propagate_error(error, g_steal_pointer(&tmp_error));
return FALSE;
+ }
+
+ /*
+ * SciTECO code must always be UTF-8, but you can smuggle arbitrary bytes
+ * into the "\e" register.
+ * This would be cumbersome to test for in teco_state_start_cmdline_pop().
+ */
+ if (!teco_string_validate_utf8(new_cmdline)) {
+ g_set_error_literal(&tmp_error, TECO_ERROR, TECO_ERROR_CODEPOINT,
+ "Invalid UTF-8 byte sequence in command-line replacement");
+ teco_error_add_frame_toplevel();
+ teco_error_display_short(tmp_error);
+ g_propagate_error(error, g_steal_pointer(&tmp_error));
+ return FALSE;
+ }
/*
* Search for first differing character in old and
@@ -229,7 +249,7 @@ teco_cmdline_insert(const gchar *data, gsize len, GError **error)
}
}
- /* error is handled in teco_cmdline_keypress_c() */
+ /* error is handled in teco_cmdline_keypress() */
g_propagate_error(error, g_steal_pointer(&tmp_error));
return FALSE;
}
diff --git a/src/string-utils.c b/src/string-utils.c
index e9dd148..d98b6b0 100644
--- a/src/string-utils.c
+++ b/src/string-utils.c
@@ -87,8 +87,10 @@ teco_string_get_coord(const gchar *str, gsize off, guint *pos, guint *line, guin
}
/**
- * Get the length of the prefix common to two strings.
- * Works with UTF-8 and single-byte encodings.
+ * Get the length of the prefix common to two UTF-8 strings.
+ *
+ * The UTF-8 strings must be validated, which should be the case
+ * for help labels and short Q-Register names.
*
* @param a Left string.
* @param b Right string.
@@ -103,8 +105,8 @@ teco_string_diff(teco_string_t a, const gchar *b, gsize b_len)
gsize len = 0;
while (len < a.len && len < b_len &&
- a.data[len] == b[len])
- len++;
+ g_utf8_get_char(a.data+len) == g_utf8_get_char(b+len))
+ len = g_utf8_next_char(b+len) - b;
return len;
}