Modify

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#8284 closed defect (fixed)

verify_custom_field pattern for name is out of date with respect to Trac

Reported by: pipern Owned by: Odd Simon Simonsen
Priority: normal Component: CustomFieldAdminPlugin
Severity: normal Keywords:
Cc: Trac Release: 0.12

Description

See trac:#2431 for the pattern they use. At time of writing: http://trac.edgewall.org/browser/trunk/trac/ticket/api.py?rev=10341#L340

Here is a patch:

  • plugins/open/customfieldadminplugin/customfieldadmin/api.py

    a b class CustomFields(Component): 
    5555        # Use lowercase custom fieldnames only
    5656        customfield['name'] = customfield['name'].lower()
    5757        # Only alphanumeric characters (and [-_]) allowed for custom fieldname
    58         if re.search('^[a-z0-9-_]+$', customfield['name']) == None:
    59            raise TracError("Only alphanumeric characters allowed for custom field name (a-z or 0-9 or -_).")
     58        # expression should match ticket/api.py pattern for "Invalid name".
     59        if re.search('^[a-zA-Z][a-zA-Z0-9_]+$', customfield['name']) == None:
     60           raise TracError("Only alphanumeric characters allowed for custom field name (a-z or 0-9 or _).")
    6061        # Check that it is a valid field type
    6162        if not customfield['type'] in ['text', 'checkbox', 'select', 'radio', 'textarea']:
    6263            raise TracError("%s is not a valid field type" % customfield['type'])

Trac seems to allow mixed case, but this plugin doesn't. I've not changed that, and this plugin still forces to lower case.

Attachments (0)

Change History (4)

comment:1 Changed 6 years ago by Odd Simon Simonsen

The underlying option parser is case-insensitive, so MYFIELD = text and myfield = text is identical when parsed. That is why I just keep all use in the plugin lower-case and also do a .lower() on the name before the regexp. So Trac allows same case just because it does not matter. However, Trac only reads so it does not care. Seeing the plugin both reads, evaluates, compares and writes, doing a same-case standardization just makes sense for me.

The only real difference is in fact that the plugin allows use of the dash ('-') character in names whereas Trac won't allow it. Looking back at current 0.11-stable it isn't allowed there either. I should change that.

comment:2 Changed 6 years ago by Odd Simon Simonsen

Ah. One more thing. only 'a-z' is allowed as first character. I'll add that too.

comment:3 Changed 6 years ago by Odd Simon Simonsen

Resolution: fixed
Status: newclosed

(In [9628]) CustomFieldAdminPlugin: Updated the 'allowed-names' regexp pattern to match the naming pattern allowed by Trac when it reads the config. Changes:

  • First character must be 'a-z'
  • Dash '-' not allowed in field name

Thanks to pipern for bug report. Closes #8284.

comment:4 Changed 6 years ago by Odd Simon Simonsen

(In [9629]) CustomFieldAdminPlugin: Follow-up to [9628], improve the error message and make it report what the regexp actually checks.

See #8284

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Odd Simon Simonsen.
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.