[PATCH stable] hgweb: catch ParseError that's raised by revset.match()

Anton Shestakov av6 at dwimlabs.net
Thu Aug 9 06:11:45 UTC 2018


# HG changeset patch
# User Anton Shestakov <av6 at dwimlabs.net>
# Date 1533791092 -28800
#      Thu Aug 09 13:04:52 2018 +0800
# Branch stable
# Node ID 8ae23d0e1367cc82e54d304bcef87ab42bada974
# Parent  c9e6ca31cfe7bed4903fa129b7d2598487d97c67
hgweb: catch ParseError that's raised by revset.match()

Some queries, like the demonstrated "first(::)", fail earlier than we call
mfunc(), and that results in a "500 Internal Server Error". To prevent it,
revset.match() also needs to be in a try-except block.

diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py
+++ b/mercurial/hgweb/webcommands.py
@@ -276,9 +276,9 @@ def _search(web):
         if not funcsused.issubset(revset.safesymbols):
             return MODE_KEYWORD, query
 
-        mfunc = revset.match(web.repo.ui, revdef,
-                             lookup=revset.lookupfn(web.repo))
         try:
+            mfunc = revset.match(web.repo.ui, revdef,
+                                 lookup=revset.lookupfn(web.repo))
             revs = mfunc(web.repo)
             return MODE_REVSET, revs
             # ParseError: wrongly placed tokens, wrongs arguments, etc
diff --git a/tests/test-hgweb-commands.t b/tests/test-hgweb-commands.t
--- a/tests/test-hgweb-commands.t
+++ b/tests/test-hgweb-commands.t
@@ -1227,6 +1227,16 @@ Search with revset syntax
   # Mode literal keyword search
   
   
+  $ get-with-headers.py $LOCALIP:$HGPORT 'log?rev=first(::)&style=raw'
+  200 Script output follows
+  
+  
+  # HG changesets search
+  # Node ID cad8025a2e87f88c06259790adfa15acb4080123
+  # Query "first(::)"
+  # Mode literal keyword search
+  
+  
 
 Revset query with foo-bar bookmark (issue5879)
 


More information about the Mercurial-devel mailing list