[gtksourceview] vim: validate tabstop and shiftwidth value
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] vim: validate tabstop and shiftwidth value
- Date: Wed, 24 Nov 2021 18:03:05 +0000 (UTC)
commit 4685e461e4c2b73bd556c50656ba2267e5195c16
Author: Christian Hergert <chergert redhat com>
Date: Wed Nov 24 12:02:53 2021 -0600
vim: validate tabstop and shiftwidth value
Fixes #237
gtksourceview/vim/gtksourcevimcommand.c | 6 ++++--
testsuite/test-vim-input.c | 12 ++++++++++++
2 files changed, 16 insertions(+), 2 deletions(-)
---
diff --git a/gtksourceview/vim/gtksourcevimcommand.c b/gtksourceview/vim/gtksourcevimcommand.c
index 46b9bf65..d4c6aa32 100644
--- a/gtksourceview/vim/gtksourcevimcommand.c
+++ b/gtksourceview/vim/gtksourcevimcommand.c
@@ -1134,7 +1134,8 @@ gtk_source_vim_command_set (GtkSourceVimCommand *self)
if (parse_number (ts, &n))
{
- gtk_source_view_set_tab_width (view, CLAMP (n, -1, 32));
+ if (n >= -1 && n != 0 && n <= 32)
+ gtk_source_view_set_tab_width (view, n);
}
}
else if (g_str_has_prefix (part, "sw=") ||
@@ -1145,7 +1146,8 @@ gtk_source_vim_command_set (GtkSourceVimCommand *self)
if (parse_number (sw, &n))
{
- gtk_source_view_set_indent_width (view, CLAMP (n, -1, 32));
+ if (n >= -1 && n != 0 && n <= 32)
+ gtk_source_view_set_indent_width (view, n);
}
}
else if (g_str_equal (part, "et") ||
diff --git a/testsuite/test-vim-input.c b/testsuite/test-vim-input.c
index c0ae334d..ceaddfa1 100644
--- a/testsuite/test-vim-input.c
+++ b/testsuite/test-vim-input.c
@@ -209,6 +209,17 @@ test_search_and_replace (void)
run_test ("/ / / /", ":s/\\//#/g\n", "# # # #");
}
+static void
+test_command_bar (void)
+{
+ run_test ("", ":set sw=0\n", "");
+ run_test ("", ":set sw=-2\n", "");
+ run_test ("", ":set sw=33\n", "");
+ run_test ("", ":set ts=0\n", "");
+ run_test ("", ":set ts=-2\n", "");
+ run_test ("", ":set ts=33\n", "");
+}
+
int
main (int argc,
char *argv[])
@@ -223,6 +234,7 @@ main (int argc,
g_test_add_func ("/GtkSourceView/vim-input/change", test_change);
g_test_add_func ("/GtkSourceView/vim-input/delete", test_delete);
g_test_add_func ("/GtkSourceView/vim-input/search-and-replace", test_search_and_replace);
+ g_test_add_func ("/GtkSourceView/vim-input/command-bar", test_command_bar);
ret = g_test_run ();
gtk_source_finalize ();
return ret;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]