nyastodon/app/validators/regexp_syntax_validator.rb

14 lines
340 B
Ruby
Raw Permalink Normal View History

2024-04-17 00:39:49 +02:00
# frozen_string_literal: true
class RegexpSyntaxValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
return if value.blank?
begin
Regexp.compile(value)
rescue RegexpError => e
record.errors.add(attribute, I18n.t('applications.invalid_regexp', message: e.message))
end
end
end