##// END OF EJS Templates
hgweb: explicitly check if requested command exists
Dirkjan Ochtman -
r5963:5be210af default
parent child Browse files
Show More
@@ -202,17 +202,18 b' class hgweb(object):'
202 try:
202 try:
203
203
204 cmd = req.form.get('cmd', [''])[0]
204 cmd = req.form.get('cmd', [''])[0]
205 if hasattr(protocol, cmd):
205 if cmd in protocol.__all__:
206 method = getattr(protocol, cmd)
206 method = getattr(protocol, cmd)
207 method(self, req)
207 method(self, req)
208 else:
208 else:
209
210 tmpl = self.templater(req)
209 tmpl = self.templater(req)
211 if cmd == '':
210 if cmd == '':
212 req.form['cmd'] = [tmpl.cache['default']]
211 req.form['cmd'] = [tmpl.cache['default']]
213 cmd = req.form['cmd'][0]
212 cmd = req.form['cmd'][0]
214
213
215 if cmd == 'file' and 'raw' in req.form.get('style', []):
214 if cmd not in webcommands.__all__:
215 raise ErrorResponse(400, 'No such method: ' + cmd)
216 elif cmd == 'file' and 'raw' in req.form.get('style', []):
216 webcommands.rawfile(self, req, tmpl)
217 webcommands.rawfile(self, req, tmpl)
217 else:
218 else:
218 getattr(webcommands, cmd)(self, req, tmpl)
219 getattr(webcommands, cmd)(self, req, tmpl)
@@ -227,8 +228,6 b' class hgweb(object):'
227 tmpl('error', error=str(inst)))
228 tmpl('error', error=str(inst)))
228 except ErrorResponse, inst:
229 except ErrorResponse, inst:
229 req.respond(inst.code, tmpl('error', error=inst.message))
230 req.respond(inst.code, tmpl('error', error=inst.message))
230 except AttributeError:
231 req.respond(400, tmpl('error', error='No such method: ' + cmd))
232
231
233 def templater(self, req):
232 def templater(self, req):
234
233
@@ -10,6 +10,14 b' from mercurial import util, streamclone'
10 from mercurial.i18n import gettext as _
10 from mercurial.i18n import gettext as _
11 from mercurial.node import *
11 from mercurial.node import *
12
12
13 # __all__ is populated with the allowed commands. Be sure to add to it if
14 # you're adding a new command, or the new command won't work.
15
16 __all__ = [
17 'lookup', 'heads', 'branches', 'between', 'changegroup',
18 'changegroupsubset', 'capabilities', 'unbundle', 'stream_out',
19 ]
20
13 def lookup(web, req):
21 def lookup(web, req):
14 try:
22 try:
15 r = hex(web.repo.lookup(req.form['key'][0]))
23 r = hex(web.repo.lookup(req.form['key'][0]))
@@ -9,6 +9,15 b' import os, mimetypes'
9 from mercurial import revlog, util, hg
9 from mercurial import revlog, util, hg
10 from common import staticfile, ErrorResponse
10 from common import staticfile, ErrorResponse
11
11
12 # __all__ is populated with the allowed commands. Be sure to add to it if
13 # you're adding a new command, or the new command won't work.
14
15 __all__ = [
16 'log', 'rawfile', 'file', 'changelog', 'shortlog', 'changeset', 'rev',
17 'manifest', 'tags', 'summary', 'filediff', 'diff', 'annotate', 'filelog',
18 'archive', 'static',
19 ]
20
12 def log(web, req, tmpl):
21 def log(web, req, tmpl):
13 if 'file' in req.form and req.form['file'][0]:
22 if 'file' in req.form and req.form['file'][0]:
14 filelog(web, req, tmpl)
23 filelog(web, req, tmpl)
General Comments 0
You need to be logged in to leave comments. Login now