summaryrefslogtreecommitdiff
path: root/app/validators
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-24 00:09:24 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-24 00:09:24 +0000
commit2711c26beaca6c3a5a3be4b65e01557faf0185b6 (patch)
tree25d0c2ddb47e87712044884f558a9104c686805f /app/validators
parent8a7aaf86831d2a556578ae558a4fcab8bb659b20 (diff)
downloadgitlab-ce-2711c26beaca6c3a5a3be4b65e01557faf0185b6.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/validators')
-rw-r--r--app/validators/untrusted_regexp_validator.rb12
1 files changed, 12 insertions, 0 deletions
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