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

login
register
mail settings
Submitter Anton Shestakov
Date Aug. 9, 2018, 6:11 a.m.
Message ID <8ae23d0e1367cc82e54d.1533795105@neuro>
Download mbox | patch
Permalink /patch/33436/
State Accepted
Headers show

Comments

Anton Shestakov - Aug. 9, 2018, 6:11 a.m.
# HG changeset patch
# User Anton Shestakov <av6@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.
Yuya Nishihara - Aug. 9, 2018, 11:50 a.m.
On Thu, 09 Aug 2018 14:11:45 +0800, Anton Shestakov wrote:
> # HG changeset patch
> # User Anton Shestakov <av6@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()

Good catch. Queued for stable, thanks.
Anton Shestakov - Aug. 9, 2018, 12:04 p.m.
On Thu, 9 Aug 2018 20:50:50 +0900
Yuya Nishihara <yuya@tcha.org> wrote:

> Good catch.

This actually was discovered by Kim Alvefur (zash on #mercurial). I
think it's worth putting a note in the message (I forgot, my bad).

Patch

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)