##// END OF EJS Templates
hgweb: respond HTTP_NOT_FOUND when an archive request does not match any files
Angel Ezquerra -
r18968:7d2a7f8e default
parent child Browse files
Show More
@@ -819,15 +819,16 b' def archive(web, req, tmpl):'
819
819
820 ctx = webutil.changectx(web.repo, req)
820 ctx = webutil.changectx(web.repo, req)
821 pats = []
821 pats = []
822 matchfn = None
822 file = req.form.get('file', None)
823 file = req.form.get('file', None)
823 if file:
824 if file:
824 file = file[0]
825 pats = ['path:' + file[0]]
825 patandfile = file.split(':')
826 matchfn = scmutil.match(ctx, pats, default='path')
826 if len(patandfile) > 1 and patandfile[0].lower() in ('glob', 'relglob',
827 if pats:
827 'path', 'relpath', 're', 'relre', 'set'):
828 files = [f for f in ctx.manifest().keys() if matchfn(f)]
828 msg = 'Archive pattern not allowed: %s' % file
829 if not files:
829 raise ErrorResponse(HTTP_FORBIDDEN, msg)
830 raise ErrorResponse(HTTP_NOT_FOUND,
830 pats = ['path:' + file]
831 'file(s) not found: %s' % file[0])
831
832
832 mimetype, artype, extension, encoding = web.archive_specs[type_]
833 mimetype, artype, extension, encoding = web.archive_specs[type_]
833 headers = [
834 headers = [
@@ -838,7 +839,6 b' def archive(web, req, tmpl):'
838 req.headers.extend(headers)
839 req.headers.extend(headers)
839 req.respond(HTTP_OK, mimetype)
840 req.respond(HTTP_OK, mimetype)
840
841
841 matchfn = scmutil.match(ctx, pats, default='path')
842 archival.archive(web.repo, req, cnode, artype, prefix=name,
842 archival.archive(web.repo, req, cnode, artype, prefix=name,
843 matchfn=matchfn,
843 matchfn=matchfn,
844 subrepos=web.configbool("web", "archivesubrepos"))
844 subrepos=web.configbool("web", "archivesubrepos"))
@@ -108,10 +108,15 b' test that we can download single directo'
108 $ python getarchive.py "$TIP" gz foo | gunzip | tar tf - 2>/dev/null
108 $ python getarchive.py "$TIP" gz foo | gunzip | tar tf - 2>/dev/null
109 test-archive-2c0277f05ed4/foo
109 test-archive-2c0277f05ed4/foo
110
110
111 test that we detect file patterns that match no files
112
113 $ python getarchive.py "$TIP" gz foobar
114 HTTP Error 404: file(s) not found: foobar
115
111 test that we reject unsafe patterns
116 test that we reject unsafe patterns
112
117
113 $ python getarchive.py "$TIP" gz relre:baz
118 $ python getarchive.py "$TIP" gz relre:baz
114 HTTP Error 403: Archive pattern not allowed: relre:baz
119 HTTP Error 404: file(s) not found: relre:baz
115
120
116 $ "$TESTDIR/killdaemons.py" $DAEMON_PIDS
121 $ "$TESTDIR/killdaemons.py" $DAEMON_PIDS
117
122
General Comments 0
You need to be logged in to leave comments. Login now