Files
gitlab-foss/app/validators/untrusted_regexp_validator.rb
2020-03-24 00:09:24 +00:00

13 lines
309 B
Ruby

# frozen_string_literal: true
class UntrustedRegexpValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
return unless value
Gitlab::UntrustedRegexp.new(value)
rescue RegexpError => e
record.errors.add(attribute, "not valid RE2 syntax: #{e.message}")
end
end