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/color_validator.rb')
-rw-r--r--app/validators/color_validator.rb10
1 files changed, 6 insertions, 4 deletions
diff --git a/app/validators/color_validator.rb b/app/validators/color_validator.rb
index 974dfbbf394..d108e4c5426 100644
--- a/app/validators/color_validator.rb
+++ b/app/validators/color_validator.rb
@@ -12,11 +12,13 @@
# end
#
class ColorValidator < ActiveModel::EachValidator
- PATTERN = /\A\#(?:[0-9A-Fa-f]{3}){1,2}\Z/.freeze
-
def validate_each(record, attribute, value)
- unless value =~ PATTERN
- record.errors.add(attribute, "must be a valid color code")
+ case value
+ when NilClass then return
+ when ::Gitlab::Color then return if value.valid?
+ when ::String then return if ::Gitlab::Color.new(value).valid?
end
+
+ record.errors.add(attribute, "must be a valid color code")
end
end