[PATCH 4 of 6 stable] hgweb: avoid traceback when file or node parameters are missing

Ross Lagerwall rosslagerwall at gmail.com
Mon Jul 30 05:09:37 CDT 2012


# HG changeset patch
# User Ross Lagerwall <rosslagerwall at gmail.com>
# Date 1343638930 -7200
# Branch stable
# Node ID 77f6a12199aeb8ac3c66de13184bc819b80f3a35
# Parent  dee588066c867ced04e2abf65e15bdd580c67152
hgweb: avoid traceback when file or node parameters are missing

Previously, browsing to http://serv/diff would generate an internal
server error due to the file and node parameters being missing.
The same error also occurred for filelog, comparison and annotate.

diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py
+++ b/mercurial/hgweb/webcommands.py
@@ -586,6 +586,8 @@
 
 def comparison(web, req, tmpl):
     ctx = webutil.changectx(web.repo, req)
+    if 'file' not in req.form:
+        raise ErrorResponse(HTTP_NOT_FOUND, 'file not given')
     path = webutil.cleanpath(web.repo, req.form['file'][0])
     rename = path in ctx and webutil.renamelink(ctx[path]) or []
 
diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py
--- a/mercurial/hgweb/webutil.py
+++ b/mercurial/hgweb/webutil.py
@@ -10,6 +10,8 @@
 from mercurial import match, patch, scmutil, error, ui, util
 from mercurial.i18n import _
 from mercurial.node import hex, nullid
+from common import ErrorResponse
+from common import HTTP_NOT_FOUND
 import difflib
 
 def up(p):
@@ -154,11 +156,15 @@
     return ctx
 
 def filectx(repo, req):
+    if 'file' not in req.form:
+        raise ErrorResponse(HTTP_NOT_FOUND, 'file not given')
     path = cleanpath(repo, req.form['file'][0])
     if 'node' in req.form:
         changeid = req.form['node'][0]
+    elif 'filenode' in req.form:
+        changeid = req.form['filenode'][0]
     else:
-        changeid = req.form['filenode'][0]
+        raise ErrorResponse(HTTP_NOT_FOUND, 'node or filenode not given')
     try:
         fctx = repo[changeid][path]
     except error.RepoError:


More information about the Mercurial-devel mailing list