sideband: color lines with keyword only

When bf1a11f0a1 (sideband: highlight keywords in remote sideband output, 2018-08-07) was introduced, it was carefully considered which strings would be highlighted. However 59a255aef0 (sideband: do not read beyond the end of input, 2018-08-18) brought in a regression that the original did not test for. A line containing only the keyword and nothing else ("SUCCESS") should still be colored. Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stefan Beller committed Dec 3, 2018 at 14:37 UTC 1f672904508c9c4e722efaf6bb8696b2e7b9d8e0
2 files changed +5 -2
sideband.c
+3 -2
@@ -87,7 +87,7 @@ static void maybe_colorize_sideband(struct strbuf *dest, const char *src, int n)
87 struct keyword_entry *p = keywords + i;
88 int len = strlen(p->keyword);
89
90 - if (n <= len)
90 + if (n < len)
91 continue;
92 /*
93 * Match case insensitively, so we colorize output from existing
@@ -95,7 +95,8 @@ static void maybe_colorize_sideband(struct strbuf *dest, const char *src, int n)
95 * messages. We only highlight the word precisely, so
96 * "successful" stays uncolored.
97 */
98 - if (!strncasecmp(p->keyword, src, len) && !isalnum(src[len])) {
98 + if (!strncasecmp(p->keyword, src, len) &&
99 + (len == n || !isalnum(src[len]))) {
100 strbuf_addstr(dest, p->color);
101 strbuf_add(dest, src, len);
102 strbuf_addstr(dest, GIT_COLOR_RESET);
t/t5409-colorize-remote-messages.sh
+2
@@ -17,6 +17,7 @@ test_expect_success 'setup' '
17 echo " " "error: leading space"
18 echo " "
19 echo Err
20 + echo SUCCESS
21 exit 0
22 EOF
23 echo 1 >file &&
@@ -35,6 +36,7 @@ test_expect_success 'keywords' '
36 grep "<BOLD;RED>error<RESET>: error" decoded &&
37 grep "<YELLOW>hint<RESET>:" decoded &&
38 grep "<BOLD;GREEN>success<RESET>:" decoded &&
39 + grep "<BOLD;GREEN>SUCCESS<RESET>" decoded &&
40 grep "<BOLD;YELLOW>warning<RESET>:" decoded
41 '
42