# HG changeset patch # User Valentin Gatien-Baron # Date 1589734363 14400 # Node ID f90957c947f44a2d5d221132be60a1fc66209c5a # Parent 7e7080ab8ba86e2aa2a8bd011ed491f475f2a916 grep: don't go in an infinite loop when given empty regex Differential Revision: https://phab.mercurial-scm.org/D8543 diff -r 7e7080ab8ba8 -r f90957c947f4 mercurial/commands.py --- a/mercurial/commands.py Sun May 17 12:49:12 2020 -0400 +++ b/mercurial/commands.py Sun May 17 12:52:43 2020 -0400 @@ -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 = {} diff -r 7e7080ab8ba8 -r f90957c947f4 tests/test-grep.t --- a/tests/test-grep.t Sun May 17 12:49:12 2020 -0400 +++ b/tests/test-grep.t Sun May 17 12:52:43 2020 -0400 @@ -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