From: Junio C Hamano Date: Sat, 18 Dec 2010 21:00:32 GMT Subject: Re: [PATCH v2 2/4] diff.c: implement a sanity check for word regexes Message-ID: <7vvd2qg5jj.fsf@alter.siamese.dyndns.org> In-Reply-To: Thomas Rast writes: > 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.