Patchwork D8543: grep: don't go in an infinite loop when given empty regex

login
register
mail settings
Submitter phabricator
Date May 17, 2020, 5:50 p.m.
Message ID <differential-rev-PHID-DREV-nj3j6dpytftqfrucwygt-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/46331/
State Superseded
Headers show

Comments

phabricator - May 17, 2020, 5:50 p.m.
valentin.gatienbaron created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/commands.py
  tests/test-grep.t

CHANGE DETAILS




To: valentin.gatienbaron, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/tests/test-grep.t b/tests/test-grep.t
--- a/tests/test-grep.t
+++ b/tests/test-grep.t
@@ -660,7 +660,7 @@ 
   $ echo 'added, missing' > added-missing; hg add added-missing; rm added-missing
   $ echo 'untracked' > untracked
   $ hg rm old
-  $ hg grep '[^Z]'
+  $ hg grep ''
   added:added
   new:something else
   new:modified
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -3428,8 +3428,11 @@ 
                 m = regexp.search(self.line, p)
                 if not m:
                     break
-                yield m.span()
-                p = m.end()
+                if m.end() == p:
+                    p += 1
+                else:
+                    yield m.span()
+                    p = m.end()
 
     matches = {}
     copies = {}