2023-09-29 23:09:41 +02:00
|
|
|
class ExpressionReguliereValidator < ActiveModel::Validator
|
|
|
|
def validate(record)
|
|
|
|
if record.value.present?
|
2023-10-13 14:27:03 +02:00
|
|
|
if !record.value.match?(Regexp.new(record.expression_reguliere, timeout: 5.0))
|
2023-10-13 14:27:03 +02:00
|
|
|
record.errors.add(:value, :invalid_regexp)
|
2023-09-29 23:09:41 +02:00
|
|
|
end
|
|
|
|
end
|
2023-10-13 14:27:03 +02:00
|
|
|
rescue Regexp::TimeoutError
|
|
|
|
record.errors.add(:expression_reguliere, :evil_regexp)
|
2023-09-29 23:09:41 +02:00
|
|
|
end
|
|
|
|
end
|