Mercurial > kallithea
changeset 7396:21084a951cd9 stable
hg: make __get_action command parsing simpler and safer
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Thu, 11 Oct 2018 02:06:50 +0200 |
parents | bc166701b0c5 |
children | 3ee4ac068369 |
files | kallithea/lib/base.py kallithea/lib/middleware/simplehg.py |
diffstat | 2 files changed, 6 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/lib/base.py Mon Jul 02 01:55:49 2018 +0200 +++ b/kallithea/lib/base.py Thu Oct 11 02:06:50 2018 +0200 @@ -218,7 +218,7 @@ Checks permissions using action (push/pull) user and repository name - :param action: push or pull action + :param action: 'push' or 'pull' action :param user: `User` instance :param repo_name: repository name """
--- a/kallithea/lib/middleware/simplehg.py Mon Jul 02 01:55:49 2018 +0200 +++ b/kallithea/lib/middleware/simplehg.py Thu Oct 11 02:06:50 2018 +0200 @@ -264,8 +264,7 @@ def __get_action(self, environ): """ - Maps mercurial request commands into a clone,pull or push command. - This should always return a valid command string + Maps Mercurial request commands into 'pull' or 'push'. :param environ: """ @@ -276,12 +275,10 @@ 'unbundle': 'push', 'pushkey': 'push', } for qry in environ['QUERY_STRING'].split('&'): - if qry.startswith('cmd'): - cmd = qry.split('=')[-1] - if cmd in mapping: - return mapping[cmd] - - return 'pull' + parts = qry.split('=', 1) + if len(parts) == 2 and parts[0] == 'cmd': + cmd = parts[1] + return mapping.get(cmd, 'pull') raise Exception('Unable to detect pull/push action !!' 'Are you using non standard command or client ?')