diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-03-03 00:20:18 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-03-03 00:20:18 +0000 |
commit | 475d5a7a176dcb87bd1fb8d55883ad2b3b2a7955 (patch) | |
tree | 93a6467c8d82d26468ce3dcebef5a7838c5a974b /app/validators | |
parent | bd091da6d5cb036cf3c58d4ba5671f931c8381e1 (diff) | |
download | gitlab-ce-475d5a7a176dcb87bd1fb8d55883ad2b3b2a7955.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/validators')
-rw-r--r-- | app/validators/color_validator.rb | 10 |
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 |