Patchwork D2866: contrib: fix a subtle bug in check-code's regex rewriting

login
register
mail settings
Submitter phabricator
Date March 15, 2018, 2:44 p.m.
Message ID <c169ad03b734266ac5971752be983145@localhost.localdomain>
Download mbox | patch
Permalink /patch/29544/
State Not Applicable
Headers show

Comments

phabricator - March 15, 2018, 2:44 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGac635637ed2f: contrib: fix a subtle bug in check-code&#039;s regex rewriting (authored by durin42, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D2866?vs=7044&id=7066

REVISION DETAIL
  https://phab.mercurial-scm.org/D2866

AFFECTED FILES
  contrib/check-code.py

CHANGE DETAILS




To: durin42, #hg-reviewers, pulkit
Cc: pulkit, mercurial-devel

Patch

diff --git a/contrib/check-code.py b/contrib/check-code.py
--- a/contrib/check-code.py
+++ b/contrib/check-code.py
@@ -542,8 +542,11 @@ 
             for i, pseq in enumerate(pats):
                 # fix-up regexes for multi-line searches
                 p = pseq[0]
-                # \s doesn't match \n
-                p = re.sub(r'(?<!\\)\\s', r'[ \\t]', p)
+                # \s doesn't match \n (done in two steps)
+                # first, we replace \s that appears in a set already
+                p = re.sub(r'\[\\s', r'[ \\t', p)
+                # now we replace other \s instances.
+                p = re.sub(r'(?<!(\\|\[))\\s', r'[ \\t]', p)
                 # [^...] doesn't match newline
                 p = re.sub(r'(?<!\\)\[\^', r'[^\\n', p)