Skip to content

Commit

Permalink
color-words: enable REG_NEWLINE to help user
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Thomas Rast authored and Junio C Hamano committed Jan 17, 2009
1 parent 2b6a541 commit bf82940
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -1544,7 +1544,8 @@ static void builtin_diff(const char *name_a,
ecbdata.diff_words->word_regex = (regex_t *)
xmalloc(sizeof(regex_t));
if (regcomp(ecbdata.diff_words->word_regex,
o->word_regex, REG_EXTENDED))
o->word_regex,
REG_EXTENDED | REG_NEWLINE))
die ("Invalid regular expression: %s",
o->word_regex);
}
Expand Down

0 comments on commit bf82940

Please sign in to comment.