# HG changeset patch # User Pulkit Goyal <7895pulkit@gmail.com> # Date 1522325552 -19800 # Node ID 81985b9d3e74346fcbe122eaf3e06a8d67564d0e # Parent fa15068a9945d4b1d1676750d478ee523b55eafc topic-ext: restrict the format of topic names This patch restrict the format of topic names to make sure they consist only of alphanumeric, '_' and '-' characters. diff -r fa15068a9945 -r 81985b9d3e74 hgext3rd/topic/__init__.py --- a/hgext3rd/topic/__init__.py Fri Apr 06 23:42:47 2018 +0530 +++ b/hgext3rd/topic/__init__.py Thu Mar 29 17:42:32 2018 +0530 @@ -594,6 +594,12 @@ # Have some restrictions on the topic name just like bookmark name scmutil.checknewlabel(repo, topic, 'topic') + rmatch = re.match(br'[\w\-]+', topic) + if not rmatch or rmatch.group(0) != topic: + helptxt = _("topic names can only consist of alphanumeric, '-'" + " and '_' characters") + raise error.Abort(_("invalid topic name: '%s'") % topic, hint=helptxt) + compat.startpager(ui, 'topics') if list: diff -r fa15068a9945 -r 81985b9d3e74 tests/test-topic.t --- a/tests/test-topic.t Fri Apr 06 23:42:47 2018 +0530 +++ b/tests/test-topic.t Thu Mar 29 17:42:32 2018 +0530 @@ -115,6 +115,24 @@ abort: topic name cannot consist entirely of whitespaces [255] + $ hg topic 'a12#45' + abort: invalid topic name: 'a12#45' + (topic names can only consist of alphanumeric, '-' and '_' characters) + [255] + + $ hg topic 'foo bar' + abort: invalid topic name: 'foo bar' + (topic names can only consist of alphanumeric, '-' and '_' characters) + [255] + +this is trying to list topic names + $ hg topic '' + + $ hg topic '*12 B23' + abort: invalid topic name: '*12 B23' + (topic names can only consist of alphanumeric, '-' and '_' characters) + [255] + Test commit flag and help text $ echo stuff >> alpha