Class: API::Validations::Validators::UntrustedRegexp

Inherits:
Grape::Validations::Base
  • Object
show all
Defined in:
lib/api/validations/validators/untrusted_regexp.rb

Instance Method Summary collapse

Instance Method Details

#validate_param!(attr_name, params) ⇒ Object


7
8
9
10
11
12
13
14
15
# File 'lib/api/validations/validators/untrusted_regexp.rb', line 7

def validate_param!(attr_name, params)
  value = params[attr_name]
  return unless value

  Gitlab::UntrustedRegexp.new(value)
rescue RegexpError => e
  message = "is an invalid regexp: #{e.message}"
  raise Grape::Exceptions::Validation, params: [@scope.full_name(attr_name)], message: message
end