debian-mirror-gitlab/lib/api/validations/validators/untrusted_regexp.rb

20 lines
535 B
Ruby
Raw Normal View History

2020-06-23 00:09:42 +05:30
# frozen_string_literal: true
module API
module Validations
module Validators
class UntrustedRegexp < Grape::Validations::Base
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}"
2021-02-22 17:27:13 +05:30
raise Grape::Exceptions::Validation.new(params: [@scope.full_name(attr_name)], message: message)
2020-06-23 00:09:42 +05:30
end
end
end
end
end