Modify

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#13220 closed enhancement (fixed)

Prevent reserved field name when adding a field via form

Reported by: Jun Omae Owned by: jomae
Priority: normal Component: CustomFieldAdminPlugin
Severity: normal Keywords:
Cc: Trac Release:

Description

Trac ignores reserved names in custom fields.

2017-06-22 19:53:07,790 (7fe956e49700) WARNING: Field name "group" is a reserved name (ignoring)

We could validate a field name is not listed in TicketSystem.reserved_field_names. The reserved_field_names property is available since Trac-0.11.3 (introduced in trac:r7769).

At trac:source:/tags/trac-1.0.15/trac/ticket/api.py@:352-354,365-367#L347]:

352             if field['name'] in self.reserved_field_names:
353                 self.log.warning('Field name "%s" is a reserved name '
354                                  '(ignoring)', field['name'])
355                 continue
...
365     reserved_field_names = ['report', 'order', 'desc', 'group', 'groupdesc',
366                             'col', 'row', 'format', 'max', 'page', 'verbose',
367                             'comment', 'or']
  • customfieldadminplugin/0.11/customfieldadmin/api.py

    diff --git a/customfieldadminplugin/0.11/customfieldadmin/api.py b/customfieldadminplugin/0.11/customfieldadmin/api.py
    index b8349f765..85f8012e3 100644
    a b class CustomFields(Component): 
    100100            raise TracError(_("Only alphanumeric characters allowed for " \
    101101                             "custom field name ('a-z' or '0-9' or '_'), " \
    102102                             "with 'a-z' as first character."))
     103        tktsys = TicketSystem(self.env)
     104        if cfield['name'] in tktsys.reserved_field_names:
     105            raise TracError(_("Field name is reserved"))
    103106        # Name must begin with a character - anything else not supported by Trac
    104107        if not cfield['name'][0].isalpha():
    105108            raise TracError(
    class CustomFields(Component): 
    113116        # (if modify it should already be deleted)
    114117        if create and self.config.get('ticket-custom', cfield['name']):
    115118            raise TracError(_("Can not create as field already exists."))
    116         if create and [f for f in TicketSystem(self.env).fields
     119        if create and [f for f in tktsys.fields
    117120                       if f['name'] == cfield['name']]:
    118121                raise TracError(_("Can't create a custom field with the "
    119122                                  "same name as a built-in field."))

Attachments (0)

Change History (3)

comment:1 Changed 7 years ago by Ryan J Ollos

Resolution: fixed
Status: newclosed

In 16676:

TracCustomFieldAdmin 0.2.13: Prevent using reserved field name

Patch by Jun Omae.

Fixes #13220.

comment:2 Changed 7 years ago by Ryan J Ollos

Owner: changed from osimons to jomae

I'll also incorporate into the branch I'm preparing for trac:#11469.

comment:3 Changed 7 years ago by Jun Omae

In 16677:

TracCustomFieldAdmin 0.2.13: follow up to [16676], fix reserved names check being case-sensitive and add unit tests for reserved field names (refs #13220)

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain jomae.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.