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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
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