Regex reject pattern from Fedibird

This commit is contained in:
Mike Barnes 2025-03-27 21:01:08 +11:00
commit 9ee03ac660
9 changed files with 57 additions and 1 deletions

View file

@ -0,0 +1,11 @@
# frozen_string_literal: true
class RegexpSyntaxValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
return if value.blank?
Regexp.compile(value)
rescue RegexpError => e
record.errors.add(attribute, I18n.t('applications.invalid_regexp', message: e.message))
end
end