Mercurial > public > mercurial-scm > evolve
diff hgext3rd/topic/__init__.py @ 6612:94bf2f307b75 stable
topic: check that topic namespace names are human-readable like topics
author | Anton Shestakov <av6@dwimlabs.net> |
---|---|
date | Mon, 11 Dec 2023 16:51:27 -0300 |
parents | 1dc008b6ad21 |
children | e0596b012b69 4443117fdf94 |
line wrap: on
line diff
--- a/hgext3rd/topic/__init__.py Mon Dec 11 16:27:09 2023 -0300 +++ b/hgext3rd/topic/__init__.py Mon Dec 11 16:51:27 2023 -0300 @@ -1841,6 +1841,18 @@ if b'/' in tns: raise error.Abort(_(b"topic namespace cannot contain '/' character")) scmutil.checknewlabel(repo, tns, b'topic namespace') + + helptxt = _(b"topic namespace names can only consist of alphanumeric, " + b"'-', '_' and '.' characters") + try: + utns = encoding.unifromlocal(tns) + except error.Abort: + # Maybe we should allow these topic names as well, as long as they + # don't break any other rules + utns = '' + rmatch = re.match(r'[-_.\w]+', utns, re.UNICODE) + if not utns or not rmatch or rmatch.group(0) != utns: + raise compat.InputError(_(b"invalid topic namespace name: '%s'") % tns, hint=helptxt) ctns = repo.currenttns _changecurrenttns(repo, tns) if ctns == b'none' and tns != b'none':