[PATCH 3 of 3 RFC STABLE] hgweb: handle invalid requests with both form data and querystring
Mads Kiilerich
mads at kiilerich.com
Fri Feb 18 20:18:34 CST 2011
# HG changeset patch
# User Mads Kiilerich <mads at kiilerich.com>
# Date 1298081745 -3600
# Branch stable
# Node ID 27ffe5140ec9b7911a02d8386c7c1b4ea421c2b8
# Parent b1ef6f31f8d7982423ef602cb42c40f3d263aaeb
hgweb: handle invalid requests with both form data and querystring
Access to invalid urls could give an unhandled ErrorResponse. This change
expands the try/except next to it to catch that.
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
@@ -114,17 +114,17 @@
cmd = req.form.get('cmd', [''])[0]
if protocol.iscmd(cmd):
- if query:
- raise ErrorResponse(HTTP_NOT_FOUND)
- if cmd in perms:
- try:
+ try:
+ if query:
+ raise ErrorResponse(HTTP_NOT_FOUND)
+ if cmd in perms:
self.check_perm(req, perms[cmd])
- except ErrorResponse, inst:
- if cmd == 'unbundle':
- req.drain()
- req.respond(inst, protocol.HGTYPE)
- return '0\n%s\n' % inst.message
- return protocol.call(self.repo, req, cmd)
+ return protocol.call(self.repo, req, cmd)
+ except ErrorResponse, inst:
+ if cmd == 'unbundle':
+ req.drain()
+ req.respond(inst, protocol.HGTYPE)
+ return '0\n%s\n' % inst.message
# translate user-visible url structure to internal structure
diff --git a/tests/test-http.t b/tests/test-http.t
--- a/tests/test-http.t
+++ b/tests/test-http.t
@@ -11,7 +11,7 @@
adding foo.d/bAr.hg.d/BaR
adding foo.d/baR.d.hg/bAR
adding foo.d/foo
- $ hg serve -p $HGPORT -d --pid-file=../hg1.pid
+ $ hg serve -p $HGPORT -d --pid-file=../hg1.pid -E ../error.log
$ hg --config server.uncompressed=False serve -p $HGPORT1 -d --pid-file=../hg2.pid
Test server address cannot be reused
@@ -85,3 +85,13 @@
changegroup hook: HG_NODE=5fed3813f7f5e1824344fdc9cf8f63bb662c292d HG_SOURCE=pull HG_URL=http://localhost:$HGPORT1/
(run 'hg update' to get a working copy)
$ cd ..
+
+clone from invalid URL
+
+ $ hg clone http://localhost:$HGPORT/bad
+ abort: HTTP Error 404: Not Found
+ [255]
+
+check error log
+
+ $ cat error.log
More information about the Mercurial-devel
mailing list