Project

General

Profile

Actions

Defect #43521

open

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

Added by Go MAEDA about 23 hours ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
Custom fields
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
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

cf-regexp-error.patch (1.05 KB) cf-regexp-error.patch Go MAEDA, 2025-11-25 04:46

No data to display

Actions

Also available in: Atom PDF