Re: [PATCH v2 2/4] diff.c: implement a sanity check for word regexes
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Dec 18, 2010, 21:00 UTC
- Message-ID
- <7vvd2qg5jj.fsf@alter.siamese.dyndns.org>
- In-Reply-To
- <ee3026bd997fc6d8508b8e5617e572f99c8bf3d6.1292688058.git.trast@student.ethz.ch>
Thomas Rast <trast@student.ethz.ch> writes:
Show 15 quoted lines
> Word regexes are a bit of a dangerous beast, since it is easily > possible to not match a non-space part, which is subsequently ignored > for the purposes of emitting the word diff. This was clearly stated > in the docs, but users still tripped over it. > > Implement a safeguard that verifies two basic sanity assumptions: > > * The word regex matches anything that is !isspace(). > > * The word regex does not match '\n'. (This case is not very harmful, > but we used to silently cut off at the '\n' which may go against > user expectations.) > > This is configurable via 'diff.wordRegexCheck', and defaults to > 'warn'.
How expensive to run this check twice, every time word_regex finds a match?
As this is about making sure that we got a sane regex from the user (or a builtin pattern), I wonder if we can make it not depend on the payload we are matching the regex against. Then before using a word_regex that we have not checked, we check if that regex is sane, mark it checked, and do not have to do the check over and over again.