fix(champ regex): same timeout across validations, and more agressive value
This commit is contained in:
parent
dbd0e82b09
commit
f4e3d2137b
2 changed files with 4 additions and 2 deletions
|
@ -618,7 +618,7 @@ class TypeDeChamp < ApplicationRecord
|
|||
def invalid_regexp?
|
||||
return false if expression_reguliere.blank?
|
||||
return false if expression_reguliere_exemple_text.blank?
|
||||
return false if expression_reguliere_exemple_text.match?(Regexp.new(expression_reguliere, timeout: 2.0))
|
||||
return false if expression_reguliere_exemple_text.match?(Regexp.new(expression_reguliere, timeout: ExpressionReguliereValidator::TIMEOUT))
|
||||
|
||||
self.errors.add(:expression_reguliere_exemple_text, I18n.t('errors.messages.mismatch_regexp'))
|
||||
true
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
class ExpressionReguliereValidator < ActiveModel::Validator
|
||||
TIMEOUT = 1.second.freeze
|
||||
|
||||
def validate(record)
|
||||
if record.value.present?
|
||||
if !record.value.match?(Regexp.new(record.expression_reguliere, timeout: 5.0))
|
||||
if !record.value.match?(Regexp.new(record.expression_reguliere, timeout: TIMEOUT))
|
||||
record.errors.add(:value, :invalid_regexp, expression_reguliere_error_message: record.expression_reguliere_error_message)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue