# HG changeset patch # User Pulkit Goyal <7895pulkit@gmail.com> # Date 2017-07-28 02:12:55 # Node ID 27fbca750b4d3eda1642626560f11fbdbf5b37f0 # Parent 850d2ec2cf6a266987a401752c909f95dd8c4c53 commitextras: make sure keys contains ascii letters, numbers, '_' and '-' only diff --git a/hgext/commitextras.py b/hgext/commitextras.py --- a/hgext/commitextras.py +++ b/hgext/commitextras.py @@ -9,6 +9,8 @@ from __future__ import absolute_import +import re + from mercurial.i18n import _ from mercurial import ( commands, @@ -52,6 +54,10 @@ def _commit(orig, ui, repo, *pats, **opt "KEY=VALUE format") raise error.Abort(msg % raw) k, v = raw.split('=', 1) + if re.search('[^\w-]', k): + msg = _("keys can only contain ascii letters, digits," + " '_' and '-'") + raise error.Abort(msg) if k in usedinternally: msg = _("key '%s' is used internally, can't be set " "manually") diff --git a/tests/test-commit.t b/tests/test-commit.t --- a/tests/test-commit.t +++ b/tests/test-commit.t @@ -135,6 +135,9 @@ Using the advanced --extra flag $ hg commit -m "adding internal used extras" --extra amend_source=hash abort: key 'amend_source' is used internally, can't be set manually [255] + $ hg commit -m "special chars in extra" --extra id@phab=214 + abort: keys can only contain ascii letters, digits, '_' and '-' + [255] $ hg commit -m "adding extras" --extra sourcehash=foo --extra oldhash=bar $ hg log -r . -T '{extras % "{extra}\n"}' branch=default