[Request] [+ ] D8543: grep: don't go in an infinite loop when given empty regex

valentin.gatienbaron (Valentin Gatien-Baron) phabricator at mercurial-scm.org
Sun May 17 17:50:04 UTC 2020


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

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 = {}



To: valentin.gatienbaron, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mercurial-scm.org/pipermail/mercurial-patches/attachments/20200517/4da3ccf9/attachment-0001.html>


More information about the Mercurial-patches mailing list