Welcome to mirror list, hosted at ThFree Co, Russian Federation.

untrusted_regexp.rb « validators « validations « api « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3ddea2bd9deee8e3a6e1d49e48adca4c3a5698fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 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}"
          raise Grape::Exceptions::Validation.new(params: [@scope.full_name(attr_name)], message: message)
        end
      end
    end
  end
end