Commits

Brodie Rao committed 40c40c6

revset: handle re.compile() errors in grep()

Raise error.ParseError instead of allowing re.error to bubble up.

  • Participants
  • Parent commits 381f131
  • Branches stable

Comments (0)

Files changed (3)

mercurial/revset.py

     return l
 
 def grep(repo, subset, x):
-    gr = re.compile(getstring(x, _("grep wants a string")))
+    try:
+        gr = re.compile(getstring(x, _("grep wants a string")))
+    except re.error, e:
+        raise error.ParseError(_('invalid match pattern: %s') % e)
     l = []
     for r in subset:
         c = repo[r]

tests/test-revset

 log 'file(b)'
 log 'follow()'
 log 'grep("issue\d+")'
+try 'grep("(")' # invalid regular expression
 log 'head()'
 log 'heads(6::)'
 log 'keyword(issue)'

tests/test-revset.out

 9
 % log 'grep("issue\d+")'
 6
+% hg debugrevspec grep("(")
+('func', ('symbol', 'grep'), ('string', '('))
+hg: parse error: invalid match pattern: unbalanced parenthesis
 % log 'head()'
 0
 1