summaryrefslogtreecommitdiff
path: root/app/validators
diff options
context:
space:
mode:
authorRoger Rüttimann <roger.ruettimann@gmail.com>2018-08-30 12:53:06 +0000
committerPhil Hughes <me@iamphill.com>2018-08-30 12:53:06 +0000
commit93b9bfd93a841b7f86e6aeab3f9c5e9ede3a4503 (patch)
tree8bfec898a33d9b0b1693e73ce27a61db54881a66 /app/validators
parent3113fb848001fdea3a039295002d7752b0feebbb (diff)
downloadgitlab-ce-93b9bfd93a841b7f86e6aeab3f9c5e9ede3a4503.tar.gz
Allow whitelisting for "external collaborator by default" setting
Diffstat (limited to 'app/validators')
-rw-r--r--app/validators/js_regex_validator.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/app/validators/js_regex_validator.rb b/app/validators/js_regex_validator.rb
new file mode 100644
index 00000000000..a515af7b919
--- /dev/null
+++ b/app/validators/js_regex_validator.rb
@@ -0,0 +1,15 @@
+class JsRegexValidator < ActiveModel::EachValidator
+ def validate_each(record, attribute, value)
+ return true if value.blank?
+
+ parsed_regex = JsRegex.new(Regexp.new(value, Regexp::IGNORECASE))
+
+ if parsed_regex.source.empty?
+ record.errors.add(attribute, "Regex Pattern #{value} can not be expressed in Javascript")
+ else
+ parsed_regex.warnings.each { |warning| record.errors.add(attribute, warning) }
+ end
+ rescue RegexpError => regex_error
+ record.errors.add(attribute, regex_error.to_s)
+ end
+end