[PATCH v4 5/7] color-words: enable REG_NEWLINE to help user
- From
Thomas Rast <trast@student.ethz.ch>
- Date
- Jan 17, 2009, 16:29 UTC
- Message-ID
- <1232209788-10408-6-git-send-email-trast@student.ethz.ch>
- In-Reply-To
- <1232209788-10408-5-git-send-email-trast@student.ethz.ch>
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> --- diff.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/diff.c b/diff.c index 9fb3d0d..00c661f 100644 --- a/diff.c +++ b/diff.c @@ -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); }
-- 1.6.1.315.g92577