From 2711c26beaca6c3a5a3be4b65e01557faf0185b6 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Tue, 24 Mar 2020 00:09:24 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- app/validators/untrusted_regexp_validator.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 app/validators/untrusted_regexp_validator.rb (limited to 'app/validators') diff --git a/app/validators/untrusted_regexp_validator.rb b/app/validators/untrusted_regexp_validator.rb new file mode 100644 index 00000000000..02ed7dfb4ed --- /dev/null +++ b/app/validators/untrusted_regexp_validator.rb @@ -0,0 +1,12 @@ +# 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 -- cgit v1.2.3