Regex reject pattern from Fedibird
This commit is contained in:
parent
a65bdad2ca
commit
9ee03ac660
9 changed files with 57 additions and 1 deletions
11
app/validators/regexp_syntax_validator.rb
Normal file
11
app/validators/regexp_syntax_validator.rb
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue