Commits

Anonymous committed d8ea274

Ported [2885] to 0.9-stable (fixing #2431).

Comments (0)

Files changed (1)

trac/ticket/api.py

 # Author: Jonas Borgström <jonas@edgewall.com>
 
 from __future__ import generators
+import re
 
 from trac import util
 from trac.core import *
             field = {'name': name, 'type': 'text', 'label': name.title()}
             fields.append(field)
 
-        custom_fields = self.get_custom_fields()
-        for field in custom_fields:
+        for field in self.get_custom_fields():
+            if field['name'] in [f['name'] for f in fields]:
+                self.log.warning('Duplicate field name "%s" (ignoring)',
+                                 field['name'])
+                continue
+            if not re.match('^[a-zA-Z][a-zA-Z0-9_]+$', field['name']):
+                self.log.warning('Invalid name for custom field: "%s" '
+                                 '(ignoring)', field['name'])
+                continue
             field['custom'] = True
+            fields.append(field)
 
-        return fields + custom_fields
+        return fields
 
     def get_custom_fields(self):
         fields = []