Re: [PATCH v2 2/4] diff.c: implement a sanity check for word regexes
From: Junio C Hamano <hidden>
Date: 2016-06-15 22:50:16
Thomas Rast [off-list ref] 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.