Details
Details
- Reviewers
dlax pulkit - Group Reviewers
hg-reviewers - Commits
- rHG6ff1a0d109c9: hgweb: fix a few `str` type conditional for py3
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
( )
| dlax | |
| pulkit |
| hg-reviewers |
| Lint Skipped |
| Unit Tests Skipped |
| Path | Packages | |||
|---|---|---|---|---|
| M | mercurial/hgweb/common.py (2 lines) | |||
| M | mercurial/hgweb/hgwebdir_mod.py (2 lines) | |||
| M | mercurial/hgweb/webcommands.py (2 lines) |
| Commit | Parents | Author | Summary | Date |
|---|---|---|---|---|
| 1021939d05bc | 49aed7ce4c05 | Matt Harbison | Nov 30 2019, 2:53 AM |
| Status | Author | Revision | |
|---|---|---|---|
| Closed | mharbison72 | ||
| Closed | dlax | ||
| Closed | mharbison72 | ||
| Closed | mharbison72 | ||
| Closed | mharbison72 | ||
| Closed | mharbison72 | ||
| Closed | mharbison72 |
| Content-Type is guessed using the mimetypes module. | Content-Type is guessed using the mimetypes module. | ||||
| Return an empty string if fname is illegal or file not found. | Return an empty string if fname is illegal or file not found. | ||||
| """ | """ | ||||
| if not ispathsafe(fname): | if not ispathsafe(fname): | ||||
| return | return | ||||
| fpath = os.path.join(*fname.split(b'/')) | fpath = os.path.join(*fname.split(b'/')) | ||||
| if isinstance(directory, str): | if isinstance(directory, bytes): | ||||
| directory = [directory] | directory = [directory] | ||||
| for d in directory: | for d in directory: | ||||
| path = os.path.join(d, fpath) | path = os.path.join(d, fpath) | ||||
| if os.path.exists(path): | if os.path.exists(path): | ||||
| break | break | ||||
| try: | try: | ||||
| os.stat(path) | os.stat(path) | ||||
| ct = pycompat.sysbytes( | ct = pycompat.sysbytes( | ||||
| if virtual.startswith(b'static/') or b'static' in req.qsparams: | if virtual.startswith(b'static/') or b'static' in req.qsparams: | ||||
| if virtual.startswith(b'static/'): | if virtual.startswith(b'static/'): | ||||
| fname = virtual[7:] | fname = virtual[7:] | ||||
| else: | else: | ||||
| fname = req.qsparams[b'static'] | fname = req.qsparams[b'static'] | ||||
| static = self.ui.config(b"web", b"static", untrusted=False) | static = self.ui.config(b"web", b"static", untrusted=False) | ||||
| if not static: | if not static: | ||||
| tp = self.templatepath or templater.templatepaths() | tp = self.templatepath or templater.templatepaths() | ||||
| if isinstance(tp, str): | if isinstance(tp, bytes): | ||||
| tp = [tp] | tp = [tp] | ||||
| static = [os.path.join(p, b'static') for p in tp] | static = [os.path.join(p, b'static') for p in tp] | ||||
| staticfile(static, fname, res) | staticfile(static, fname, res) | ||||
| return res.sendresponse() | return res.sendresponse() | ||||
| # top-level index | # top-level index | ||||
| @webcommand(b'static') | @webcommand(b'static') | ||||
| def static(web): | def static(web): | ||||
| fname = web.req.qsparams[b'file'] | fname = web.req.qsparams[b'file'] | ||||
| # a repo owner may set web.static in .hg/hgrc to get any file | # a repo owner may set web.static in .hg/hgrc to get any file | ||||
| # readable by the user running the CGI script | # readable by the user running the CGI script | ||||
| static = web.config(b"web", b"static", untrusted=False) | static = web.config(b"web", b"static", untrusted=False) | ||||
| if not static: | if not static: | ||||
| tp = web.templatepath or templater.templatepaths() | tp = web.templatepath or templater.templatepaths() | ||||
| if isinstance(tp, str): | if isinstance(tp, bytes): | ||||
| tp = [tp] | tp = [tp] | ||||
| static = [os.path.join(p, b'static') for p in tp] | static = [os.path.join(p, b'static') for p in tp] | ||||
| staticfile(static, fname, web.res) | staticfile(static, fname, web.res) | ||||
| return web.res.sendresponse() | return web.res.sendresponse() | ||||
| @webcommand(b'graph') | @webcommand(b'graph') | ||||