Skip to content

Commit bf82940

Browse files
trastgitster
authored andcommitted
color-words: enable REG_NEWLINE to help user
We silently truncate a match at the newline, which may lead to unexpected behaviour, e.g., when matching "<[^>]*>" against <foo bar> since then "<foo" becomes a word (and "bar>" doesn't!) even though the regex said only angle-bracket-delimited things can be words. To alleviate the problem slightly, use REG_NEWLINE so that negated classes can't match a newline. Of course newlines can still be matched explicitly. Signed-off-by: Thomas Rast <trast@student.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 2b6a541 commit bf82940

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

diff.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1544,7 +1544,8 @@ static void builtin_diff(const char *name_a,
15441544
ecbdata.diff_words->word_regex = (regex_t *)
15451545
xmalloc(sizeof(regex_t));
15461546
if (regcomp(ecbdata.diff_words->word_regex,
1547-
o->word_regex, REG_EXTENDED))
1547+
o->word_regex,
1548+
REG_EXTENDED | REG_NEWLINE))
15481549
die ("Invalid regular expression: %s",
15491550
o->word_regex);
15501551
}

0 commit comments

Comments
 (0)