1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-30 06:46:38 +02:00

core: fix function string_cut when there are non printable chars in suffix

This commit is contained in:
Sébastien Helleu
2022-12-04 21:22:11 +01:00
parent f1cfd6f73f
commit ef842c5e62
2 changed files with 22 additions and 1 deletions
+21
View File
@@ -222,6 +222,8 @@ TEST(CoreString, Case)
TEST(CoreString, Cut)
{
char suffix[128], string[128];
POINTERS_EQUAL(NULL, string_cut (NULL, 0, 0, 0, NULL));
STRCMP_EQUAL("", string_cut ("", 0, 0, 0, NULL));
@@ -317,6 +319,25 @@ TEST(CoreString, Cut)
STRCMP_EQUAL("", string_cut ("こんにちは世界", 3, 1, 1, NULL));
STRCMP_EQUAL("こ+", string_cut ("こんにちは世界", 3, 1, 1, "+"));
STRCMP_EQUAL("こ…", string_cut ("こんにちは世界", 3, 1, 1, ""));
/* cut suffix using color and 1 char */
snprintf (suffix, sizeof (suffix), "%s+", gui_color_get_custom ("red"));
snprintf (string, sizeof (string), "te%s+", gui_color_get_custom ("red"));
STRCMP_EQUAL(string, string_cut ("test", 3, 1, 1, suffix));
/* cut suffix using color and 2 chars */
snprintf (suffix, sizeof (suffix), "%s++", gui_color_get_custom ("red"));
snprintf (string, sizeof (string), "t%s++", gui_color_get_custom ("red"));
STRCMP_EQUAL(string, string_cut ("test", 3, 1, 1, suffix));
/* cut suffix using color and 3 chars */
snprintf (suffix, sizeof (suffix), "%s+++", gui_color_get_custom ("red"));
snprintf (string, sizeof (string), "%s+++", gui_color_get_custom ("red"));
STRCMP_EQUAL(string, string_cut ("test", 3, 1, 1, suffix));
/* cut suffix using color and 4 chars */
snprintf (suffix, sizeof (suffix), "%s++++", gui_color_get_custom ("red"));
STRCMP_EQUAL("", string_cut ("test", 3, 1, 1, suffix));
}
/*