Project

General

Profile

Actions

Defect #43521

closed

Saving a custom field fails with 500 when regular expression is invalid

Added by Go MAEDA about 2 months ago. Updated 3 days ago.

Status:
Closed
Priority:
Normal
Category:
Custom fields
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed
Affected version:

Description

When a custom field has the format "Text" or "Long text", an Internal Server Error occurs on save if the "Regular expression" contains an invalid pattern and the "Default value" is not empty.

The reason is that the default value is validated using Regexp.new with the invalid pattern, which raises a RegexpError exception.

source:tags/6.1.0/lib/redmine/field_format.rb#L384:

        unless custom_field.regexp.blank? or Regexp.new(custom_field.regexp).match?(value)
          errs << ::I18n.t('activerecord.errors.messages.invalid')
        end

The attached patch is a workaround for this issue. It rescues RegexpError during the Regexp.new call and skips the regular expression validation when the pattern is invalid, preventing the Internal Server Error. The validity of the regular expression is already checked in CustomField#validate_custom_field, so ignoring RegexpError at this point is safe.

Steps to reproduce:

1. On the Administration > Custom fields page, click "New custom field".
2. Select "Issues" and click "Next".
3. Select "Text" as the "Format", enter any value in "Name", enter [ in "Regular expression", and enter any value in "Default value".
4. Click "Create".


Files

Actions #1

Updated by Marius BĂLTEANU 8 days ago

  • Status changed from New to Confirmed
  • Target version set to 6.0.8
Actions #2

Updated by Marius BĂLTEANU 8 days ago

I have added a patch with a test and an alternative method to fix this issue.

Actions #3

Updated by Marius BĂLTEANU 3 days ago

  • Status changed from Confirmed to Closed
  • Assignee set to Marius BĂLTEANU
  • Resolution set to Fixed
Actions

Also available in: Atom PDF