Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/hgweb/webcommands.py @ 18968:7d2a7f8e9da4
hgweb: respond HTTP_NOT_FOUND when an archive request does not match any files
author | Angel Ezquerra <angel.ezquerra@gmail.com> |
---|---|
date | Thu, 21 Mar 2013 23:27:37 +0100 |
parents | bb38f4f78104 |
children | afc23eddc324 |
comparison
equal
deleted
inserted
replaced
18967:88d1b59f6906 | 18968:7d2a7f8e9da4 |
---|---|
817 arch_version = short(cnode) | 817 arch_version = short(cnode) |
818 name = "%s-%s" % (reponame, arch_version) | 818 name = "%s-%s" % (reponame, arch_version) |
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 = [ |
834 ('Content-Disposition', 'attachment; filename=%s%s' % (name, extension)) | 835 ('Content-Disposition', 'attachment; filename=%s%s' % (name, extension)) |
835 ] | 836 ] |
836 if encoding: | 837 if encoding: |
837 headers.append(('Content-Encoding', encoding)) | 838 headers.append(('Content-Encoding', encoding)) |
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")) |
845 return [] | 845 return [] |
846 | 846 |