Patchwork hgweb: show 404 on missing template in current style (issue3809)

login
register
mail settings
Submitter Kevin Bullock
Date Feb. 5, 2013, 5:43 p.m.
Message ID <be8cfc33342e8277b756.1360086184@x-128-101-230-36.uofm-secure.wireless.umn.edu>
Download mbox | patch
Permalink /patch/809/
State Rejected, archived
Headers show

Comments

Kevin Bullock - Feb. 5, 2013, 5:43 p.m.
# HG changeset patch
# User Kevin Bullock <kbullock@ringworld.org>
# Date 1360084904 21600
# Branch stable
# Node ID be8cfc33342e8277b7569f3b1f4f512ca798271a
# Parent  5d02f1d86c2e172d82eba98bc3248f3101c91bc4
hgweb: show 404 on missing template in current style (issue3809)
Pierre-Yves David - Feb. 6, 2013, 8:37 a.m.
On Tue, Feb 05, 2013 at 11:43:04AM -0600, Kevin Bullock wrote:
> # HG changeset patch
> # User Kevin Bullock <kbullock@ringworld.org>
> # Date 1360084904 21600
> # Branch stable
> # Node ID be8cfc33342e8277b7569f3b1f4f512ca798271a
> # Parent  5d02f1d86c2e172d82eba98bc3248f3101c91bc4
> hgweb: show 404 on missing template in current style (issue3809)
> 
> diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py
> --- a/mercurial/hgweb/hgweb_mod.py
> +++ b/mercurial/hgweb/hgweb_mod.py
> @@ -219,7 +219,11 @@ class hgweb(object):
>              tmpl = self.templater(req)
>              ctype = tmpl('mimetype', encoding=encoding.encoding)
>              ctype = templater.stringify(ctype)
> +        except error.Abort, err:
> +            req.respond(HTTP_NOT_FOUND, ctype)
> +            return tmpl('error', error=str(err))

404 on Abort exception seems far too wide. But I did not looked the code closely.

Patch

diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py
--- a/mercurial/hgweb/hgweb_mod.py
+++ b/mercurial/hgweb/hgweb_mod.py
@@ -219,7 +219,11 @@  class hgweb(object):
             tmpl = self.templater(req)
             ctype = tmpl('mimetype', encoding=encoding.encoding)
             ctype = templater.stringify(ctype)
+        except error.Abort, err:
+            req.respond(HTTP_NOT_FOUND, ctype)
+            return tmpl('error', error=str(err))
 
+        try:
             # check read permissions non-static content
             if cmd != 'static':
                 self.check_perm(req, None)
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
@@ -1362,10 +1362,8 @@  Test paging
 
   $ cat errors.log
 
-bookmarks view doesn't choke on bookmarks on secret changesets (issue3774)
+missing template results in 404, not traceback
 
-  $ hg phase -fs 4
-  $ hg bookmark -r4 secret
   $ cat > hgweb.cgi <<HGWEB
   > from mercurial import demandimport; demandimport.enable()
   > from mercurial.hgweb import hgweb
@@ -1374,6 +1372,19 @@  bookmarks view doesn't choke on bookmark
   > wsgicgi.launch(app)
   > HGWEB
   $ . "$TESTDIR/cgienv"
+  $ PATH_INFO=/summary; export PATH_INFO
+  $ QUERY_STRING='style=raw'; export QUERY_STRING
+  $ python hgweb.cgi | grep -v ETag:
+  Status: 404 Not Found\r (esc)
+  Content-Type: text/plain; charset=ascii\r (esc)
+  \r (esc)
+  
+  error: "summary" not in template map
+
+bookmarks view doesn't choke on bookmarks on secret changesets (issue3774)
+
+  $ hg phase -fs 4
+  $ hg bookmark -r4 secret
   $ PATH_INFO=/bookmarks; export PATH_INFO
   $ QUERY_STRING='style=raw'
   $ python hgweb.cgi | grep -v ETag: