diff hgext3rd/topic/__init__.py @ 3652:81985b9d3e74

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.
author Pulkit Goyal <7895pulkit@gmail.com>
date Thu, 29 Mar 2018 17:42:32 +0530
parents 9ad461df4d4d
children a346b1641dfa
line wrap: on
line diff
--- 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: