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:
authorblackst0ne <blackst0ne.ru@gmail.com>2017-04-12 00:56:33 +0300
committerblackst0ne <blackst0ne.ru@gmail.com>2017-04-12 00:56:33 +0300
commit9a048a6ea2f0c5aeea0d366ebf715b54664a5f70 (patch)
tree3a2c85708568acdf56ee766d852e73f430bbaaa1 /app/models/label.rb
parent01adf920c4da977328c38836327681eb4c52cbee (diff)
Remove heading and trailing spaces from label's color and title
Diffstat (limited to 'app/models/label.rb')
-rw-r--r--app/models/label.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/app/models/label.rb b/app/models/label.rb
index 568fa6d44f5..d8b0e250732 100644
--- a/app/models/label.rb
+++ b/app/models/label.rb
@@ -21,6 +21,8 @@ class Label < ActiveRecord::Base
has_many :issues, through: :label_links, source: :target, source_type: 'Issue'
has_many :merge_requests, through: :label_links, source: :target, source_type: 'MergeRequest'
+ before_validation :strip_whitespace_from_title_and_color
+
validates :color, color: true, allow_blank: false
# Don't allow ',' for label titles
@@ -193,4 +195,8 @@ class Label < ActiveRecord::Base
def sanitize_title(value)
CGI.unescapeHTML(Sanitize.clean(value.to_s))
end
+
+ def strip_whitespace_from_title_and_color
+ %w(color title).each { |attr| self[attr] = self[attr]&.strip }
+ end
end