Defect #43521
closedSaving a custom field fails with 500 when regular expression is invalid
0%
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
Updated by Marius BĂLTEANU 8 days ago
- Status changed from New to Confirmed
- Target version set to 6.0.8
Updated by Marius BĂLTEANU 8 days ago
- File 0001-Fix-RegexpError-when-validating-CustomField-with-inv.patch 0001-Fix-RegexpError-when-validating-CustomField-with-inv.patch added
I have added a patch with a test and an alternative method to fix this issue.
Updated by Marius BĂLTEANU 3 days ago
- Status changed from Confirmed to Closed
- Assignee set to Marius BĂLTEANU
- Resolution set to Fixed