Commit 9a048a6e authored by blackst0ne's avatar blackst0ne

Remove heading and trailing spaces from label's color and title

parent 01adf920
...@@ -21,6 +21,8 @@ class Label < ActiveRecord::Base ...@@ -21,6 +21,8 @@ class Label < ActiveRecord::Base
has_many :issues, through: :label_links, source: :target, source_type: 'Issue' has_many :issues, through: :label_links, source: :target, source_type: 'Issue'
has_many :merge_requests, through: :label_links, source: :target, source_type: 'MergeRequest' 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 validates :color, color: true, allow_blank: false
# Don't allow ',' for label titles # Don't allow ',' for label titles
...@@ -193,4 +195,8 @@ class Label < ActiveRecord::Base ...@@ -193,4 +195,8 @@ class Label < ActiveRecord::Base
def sanitize_title(value) def sanitize_title(value)
CGI.unescapeHTML(Sanitize.clean(value.to_s)) CGI.unescapeHTML(Sanitize.clean(value.to_s))
end end
def strip_whitespace_from_title_and_color
%w(color title).each { |attr| self[attr] = self[attr]&.strip }
end
end end
---
title: Remove heading and trailing spaces from label's color and title
merge_request: 10603
author: blackst0ne
...@@ -42,11 +42,27 @@ describe Label, models: true do ...@@ -42,11 +42,27 @@ describe Label, models: true do
end end
end end
describe '#color' do
it 'strips color' do
label = described_class.new(color: ' #abcdef ')
label.valid?
expect(label.color).to eq('#abcdef')
end
end
describe '#title' do describe '#title' do
it 'sanitizes title' do it 'sanitizes title' do
label = described_class.new(title: '<b>foo & bar?</b>') label = described_class.new(title: '<b>foo & bar?</b>')
expect(label.title).to eq('foo & bar?') expect(label.title).to eq('foo & bar?')
end end
it 'strips title' do
label = described_class.new(title: ' label ')
label.valid?
expect(label.title).to eq('label')
end
end end
describe 'priorization' do describe 'priorization' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment