From 05839983d45af29a383a8e702753eb9617b4e260 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Fri, 30 Dec 2022 21:50:18 +0100 Subject: [PATCH] core: fix color when the delimiter is not followed by a background color (closes #1867) --- ChangeLog.adoc | 1 + src/gui/gui-color.c | 2 +- tests/unit/gui/test-gui-color.cpp | 12 ++++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/ChangeLog.adoc b/ChangeLog.adoc index a8d75c5ca..796a01929 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -40,6 +40,7 @@ New features:: Bug fixes:: + * core: fix color when the delimiter is not followed by a background color (issue #1867) * core: display chars the same way in chat and bars, replace tabulations by spaces in bars, display chars < 32 with letter in chat, do not display soft hyphens, zero width spaces and all non-printable chars (issue #1659, issue #1669, issue #1770) * core: fix context info in buffers with free content (issue #1832) * core: keep terminal title unchanged when option weechat.look.window_title is set to empty value (issue #1835, issue #1836) diff --git a/src/gui/gui-color.c b/src/gui/gui-color.c index 68c1e690d..e425d108e 100644 --- a/src/gui/gui-color.c +++ b/src/gui/gui-color.c @@ -424,7 +424,7 @@ gui_color_get_custom (const char *color_name) else str_fg = string_strndup (ptr_color_name, pos_delim - ptr_color_name); - pos_bg = pos_delim + 1; + pos_bg = (pos_delim[1]) ? pos_delim + 1 : NULL; } else { diff --git a/tests/unit/gui/test-gui-color.cpp b/tests/unit/gui/test-gui-color.cpp index ecf3f0951..2505c2f92 100644 --- a/tests/unit/gui/test-gui-color.cpp +++ b/tests/unit/gui/test-gui-color.cpp @@ -192,6 +192,10 @@ TEST(GuiColor, GetCustom) GUI_COLOR_BAR_BG_CHAR); STRCMP_EQUAL(string, gui_color_get_custom ("bar_bg")); + /* only delimiter (no-op) */ + STRCMP_EQUAL("", gui_color_get_custom (",")); + STRCMP_EQUAL("", gui_color_get_custom (":")); + /* fg color */ snprintf (string, sizeof (string), "%c%c09", @@ -199,6 +203,14 @@ TEST(GuiColor, GetCustom) GUI_COLOR_FG_CHAR); STRCMP_EQUAL(string, gui_color_get_custom ("blue")); + /* fg color, delimiter and no bg color */ + snprintf (string, sizeof (string), + "%c%c09", + GUI_COLOR_COLOR_CHAR, + GUI_COLOR_FG_CHAR); + STRCMP_EQUAL(string, gui_color_get_custom ("blue,")); + STRCMP_EQUAL(string, gui_color_get_custom ("blue:")); + /* bg color */ snprintf (string, sizeof (string), "%c%c09",